当前位置: 首页>>代码示例>>C#>>正文


C# UnitOfWork.GetRepository方法代码示例

本文整理汇总了C#中UnitOfWork.GetRepository方法的典型用法代码示例。如果您正苦于以下问题:C# UnitOfWork.GetRepository方法的具体用法?C# UnitOfWork.GetRepository怎么用?C# UnitOfWork.GetRepository使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnitOfWork的用法示例。


在下文中一共展示了UnitOfWork.GetRepository方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            try
            {
                using (IUnitOfWork uow = new UnitOfWork(new Guid("5B479CE2-4BBC-4F9E-8539-6A6BC2DD099D")))
                {
                    User user = null;
                    UserProfile userProfile = null;

                    uow.CreateRepository<UserProfile>();
                    uow.CreateRepository<User>();

                    var userProfileRepository = uow.GetRepository<UserProfile>();
                    var userRepository = uow.GetRepository<User>();

                    //Create Profile
                    userProfile = new UserProfile();
                    userProfile.Name = "Developpers";
                    userProfile.Description = "Developpers Group";
                    var profileAdded = userProfileRepository.Insert(userProfile);

                    //Create User
                    user = new User();
                    user.UserName = "Leonel Vasconcelos";
                    user.Login = "gurdurix";
                    user.Password = "123456";
                    user.ProfileUser = profileAdded;
                    userRepository.Insert(user);

                    uow.SaveChanges();
                    user = null;
                    userProfile = null;

                    //Get user information
                    user = userRepository.GetEntityBy(new FindEntitySpecification<User>(p=>p.Login.Equals("gurdurix")));
                    Console.WriteLine($"{user.Id} >> {user.Login} ({user.UserName})");

                    //var user = userRepository.GetEntityByPrimaryKey(new FindEntityByIdSpecification<User>(new Guid("97DD8E65-76F1-4C12-A0FA-D9D07032C81B")));
                    //uow.CreateRepository<UserProfile>();
                    //IRepository<UserProfile> userProfileRepository = uow.GetRepository<UserProfile>();
                    //userProfileRepository.Insert(new UserProfile(
                    //var users = uow.GetRepository<User>().GetAllEntities(
                    //    new FindEntitySpecification<User>(p => p.ProfileUser.ID.Equals(new Guid("E50C5924-B88B-44D7-B89A-1F30244A1817")))
                    //        .Not(new FindEntityByIdSpecification<User>(new Guid("D9579A46-1B9F-4C09-A02D-E4A6D4096E00"))));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
开发者ID:gurdurix,项目名称:EFRepositoryPattern,代码行数:51,代码来源:Program.cs

示例2: GetExpenses

 /// <summary>
 /// Gets all the expenses.
 /// </summary>
 /// <returns></returns>
 public IEnumerable<ExpenseDto> GetExpenses()
 {
     using (var uow = new UnitOfWork())
     {
         return uow.GetRepository<ExpenseRepository>().GetExpenses();
     }
 }
开发者ID:RookieOne,项目名称:GreekFire,代码行数:11,代码来源:ExpenseService.cs

示例3: Create

        public async Task<ReturnModel<ClientModel>> Create (ClientModel ClientModel)
        {
            var result = new ReturnModel<ClientModel> { Status = true };
            using(var session = new UnitOfWork<FoodMenuEntities>())
            {
                var ClientRepository = session.GetRepository<IClientRepository>();

                var client = new Client();
                client.Id = ClientModel.Id;
                client.Name = ClientModel.Name;
                client.Email = ClientModel.Email;
                client.Phone = ClientModel.Phone;
                client.Nationalid = ClientModel.Nationalid;
                client.Sex = ClientModel.Sex;
                client.Height = ClientModel.Height;
                client.Weight = ClientModel.Weight;
                client.FatPercentage = ClientModel.FatPercentage;
                client.Goal = ClientModel.Goal;
                client.Pills = ClientModel.Pills;
                client.Supplement = ClientModel.Supplement;
                client.RedirectedBy = ClientModel.RedirectedBy;
                client.Price = ClientModel.Price;
                client.RMR = ClientModel.RMR;
                client.UserId = ClientModel.UserId;
                ClientRepository.Add(client);

                await session.SaveChangesAsync();

                ClientModel.Id = client.Id;
                result.Result = ClientModel;
                return result;
            }
        }
开发者ID:mberaz,项目名称:foodMenu,代码行数:33,代码来源:ClientsBL.cs

示例4: Create

        public async Task<ReturnModel<UserModel>> Create (UserModel userModel)
        {
            var result = new ReturnModel<UserModel> { Status = true };
            using(var session = new UnitOfWork<FoodMenuEntities>())
            {
                var userRepository = session.GetRepository<IUserRepository>();

                if(!(await userRepository.ValidateEmail(userModel.Email,userModel.Id)))
                {
                    result.Error = ("כתובת האמייל כבר בשימוש.");
                    result.Status = false;
                    return result;
                }

                var user = new User();
                user.Id = userModel.Id;
                user.Email = userModel.Email;
                user.Password = userModel.Password;
                user.FirstName = userModel.FirstName;
                user.LastName = userModel.LastName;
                user.BusinessId = userModel.BusinessId;
                user.Address = userModel.Address;
                user.IsActive = true;
                userRepository.Add(user);

                await session.SaveChangesAsync();

                userModel.Id = user.Id;
                userModel.Token = Guid.NewGuid().ToString();
                result.Result = userModel;
                return result;
            }
        }
开发者ID:mberaz,项目名称:foodMenu,代码行数:33,代码来源:UsersBL.cs

示例5: GetAll

        public Task<FormatedList<InvoiceModel>> GetAll (NameValueCollection requestParams,int clientId)
        {
            return Task.Run(() =>
            {
                using(var session = new UnitOfWork<FoodMenuEntities>())
                {
                    IInvoiceRepository InvoiceRepository = session.GetRepository<IInvoiceRepository>();

                    var InvoiceList = InvoiceRepository.GetAll().Where(u => u.ClientId == clientId).Select(i => new InvoiceModel
                    {
                        Id = i.Id,
                        ClientId = i.ClientId,
                        Notes = i.Notes,
                        MeetingId = i.MeetingId,
                        Number = i.Number,
                    });

                    var parser = new DataTableEntityParser<InvoiceModel>(requestParams,InvoiceList.AsQueryable());

                    var list = parser.Parse();

                    return list;
                }
            });
        }
开发者ID:mberaz,项目名称:foodMenu,代码行数:25,代码来源:InvoiceBL.cs

示例6: GetAll

        public Task<FormatedList<UserModel>> GetAll (NameValueCollection requestParams)
        {
            return Task.Run(() =>
            {
                using(var session = new UnitOfWork<FoodMenuEntities>())
                {
                    IUserRepository userRepository = session.GetRepository<IUserRepository>();

                    var userList = userRepository.Find(u => u.IsActive).Select(u => new UserModel
                    {
                        Id = u.Id,
                        Email = u.Email,
                        Password = u.Password,
                        FirstName = u.FirstName,
                        LastName = u.LastName,
                        BusinessId = u.BusinessId,
                        Address = u.Address,
                    });

                    var parser = new DataTableEntityParser<UserModel>(requestParams,userList.AsQueryable());

                    return parser.Parse();
                }
            });
        }
开发者ID:mberaz,项目名称:foodMenu,代码行数:25,代码来源:UsersBL.cs

示例7: Create

        public async Task<ReturnModel<MeetingModel>> Create (MeetingModel meetingModel)
        {
            var result = new ReturnModel<MeetingModel> { Status = true };
            using(var session = new UnitOfWork<FoodMenuEntities>())
            {
                var MeetingRepository = session.GetRepository<IMeetingRepository>();

                var meeting = new Meeting();
                meeting.Id = meetingModel.Id;
                meeting.ClientId = meetingModel.ClientId;
                meeting.Date = meetingModel.Date;
                meeting.Weight = meetingModel.Weight;
                meeting.Water = meetingModel.Water;
                meeting.Muscle = meetingModel.Muscle;
                meeting.FatPercentage = meetingModel.FatPercentage;
                meeting.MeetingIndex = meetingModel.MeetingIndex;
                meeting.ArmMuscleMeasurement = meetingModel.ArmMuscleMeasurement;
                meeting.ArmNOMuscleMeasurement = meetingModel.ArmNOMuscleMeasurement;
                meeting.HipMeasurement = meetingModel.HipMeasurement;
                meeting.StomachMeasurement = meetingModel.StomachMeasurement;
                meeting.ThighMeasurement = meetingModel.ThighMeasurement;
                meeting.FrontHandFat = meetingModel.FrontHandFat;
                meeting.BackHandFat = meetingModel.BackHandFat;
                meeting.ThighFat = meetingModel.ThighFat;
                meeting.BackFat = meetingModel.BackFat;
                meeting.FatAvrg = meetingModel.FatAvrg;
                MeetingRepository.Add(meeting);

                await session.SaveChangesAsync();

                meetingModel.Id = meeting.Id;
                result.Result = meetingModel;
                return result;
            }
        }
开发者ID:mberaz,项目名称:foodMenu,代码行数:35,代码来源:MeetingBL.cs

示例8: SaveExpense

        public void SaveExpense(ExpenseDto expenseDto)
        {
            var expense = _expenseFactory.createFromDto<Expense>(expenseDto);

            if (expense == null)
                return;

            using (var uow = new UnitOfWork())
            {
                uow.GetRepository<ExpenseRepository>().Save(expense);
            }
        }
开发者ID:RookieOne,项目名称:GreekFire,代码行数:12,代码来源:ExpenseService.cs

示例9: BecauseOf

        protected override void BecauseOf()
        {
            _newExpense = NewExpense.create()
                .withTitle("New Expense")
                .withDescription("New Description")
                .complete();

            using (var uow = new UnitOfWork())
            {
                uow.GetRepository<ExpenseRepository>().Save(_newExpense);
                uow.Commit();
            }
        }
开发者ID:RookieOne,项目名称:GreekFire,代码行数:13,代码来源:When_saving_a_new_expense.cs

示例10: OutputExpenseRepository

        public static void OutputExpenseRepository()
        {
            Console.WriteLine("In Expense Repository ...");

            using (var uow = new UnitOfWork())
            {
                var repository = uow.GetRepository<ExpenseRepository>();

                repository.GetExpenses()
                    .ForEach(e => OutputExpense(e));
            }

            Console.WriteLine("....");
            Console.ReadLine();
        }
开发者ID:RookieOne,项目名称:GreekFire,代码行数:15,代码来源:ConsoleOutput.cs

示例11: DisplayRepository

        private static void DisplayRepository()
        {
            Console.WriteLine("In repository ...");

            using (var uow = new UnitOfWork())
            {
                var repository = uow.GetRepository<ExpenseRepository>();

                IEnumerable<Expense> expenses = repository.GetExpenses();

                foreach (Expense expense in expenses)
                    Console.WriteLine(expense.Title);
            }

            Console.WriteLine("....");
            Console.ReadLine();
        }
开发者ID:RookieOne,项目名称:GreekFire,代码行数:17,代码来源:Program.cs

示例12: ApproveExpense

        public void ApproveExpense(int id, DateTime approvalDate)
        {
            using (var uow = new UnitOfWork())
            {
                var repository = uow.GetRepository<ExpenseRepository>();

                var dto = repository.GetExpense(id);

                var expense = _expenseFactory.createFromDto<NewExpense>(dto);

                if (expense != null)
                {
                    var approvedExpense = expense.Approve(approvalDate);
                    repository.Save(approvedExpense);
                }
            }
        }
开发者ID:RookieOne,项目名称:GreekFire,代码行数:17,代码来源:ExpenseService.cs

示例13: GetAll

        public Task<FormatedList<ClientModel>> GetAll (NameValueCollection requestParams)
        {
            return Task.Run(() =>
            {
                using(var session = new UnitOfWork<FoodMenuEntities>())
                {
                    IClientRepository ClientRepository = session.GetRepository<IClientRepository>();

                    var ClientList = ClientRepository.Find(u => u.IsActive).Select(c => new ClientModel
                    {
                        Id = c.Id,
                        Name = c.Name,
                        Email = c.Email,
                        Phone = c.Phone,
                        Nationalid = c.Nationalid,
                        Sex = c.Sex,
                        Height = c.Height,
                        Weight = c.Weight,
                        FatPercentage = c.FatPercentage,
                        //Goal = c.Goal,
                        //Pills = c.Pills,
                        //Supplement = c.Supplement,
                        //RedirectedBy = c.RedirectedBy,
                        Price = c.Price,
                        //RMR = c.RMR,
                        //UserId = c.UserId,
                    });

                    var parser = new DataTableEntityParser<ClientModel>(requestParams,ClientList.AsQueryable());

                    var list = parser.Parse();
                    foreach(var item in list.aaData)
                    {
                        var itemSex = item[4].ToInt();

                        item[4] = Utility.GetDescription(itemSex,typeof(SexEnum));

                    }

                    return list;
                }
            });
        }
开发者ID:mberaz,项目名称:foodMenu,代码行数:43,代码来源:ClientsBL.cs

示例14: Create

        public async Task<ReturnModel<InvoiceModel>> Create (InvoiceModel invoiceModel)
        {
            var result = new ReturnModel<InvoiceModel> { Status = true };
            using(var session = new UnitOfWork<FoodMenuEntities>())
            {
                var InvoiceRepository = session.GetRepository<IInvoiceRepository>();

                var invoice = new Invoice();
                invoice.Id = invoiceModel.Id;
                invoice.ClientId = invoiceModel.ClientId;
                invoice.Notes = invoiceModel.Notes;
                invoice.MeetingId = invoiceModel.MeetingId;
                invoice.Number = invoiceModel.Number;
                InvoiceRepository.Add(invoice);

                await session.SaveChangesAsync();

                invoiceModel.Id = invoice.Id;
                result.Result = invoiceModel;
                return result;
            }
        }
开发者ID:mberaz,项目名称:foodMenu,代码行数:22,代码来源:InvoiceBL.cs

示例15: GetByID

        public async Task<ReturnModel<InvoiceModel>> GetByID (int invoiceID)
        {
            InvoiceModel invoiceModel = new InvoiceModel();
            using(var session = new UnitOfWork<FoodMenuEntities>())
            {
                var InvoiceRepository = session.GetRepository<IInvoiceRepository>();

                var invoice = await InvoiceRepository.GetByID(invoiceID);

                invoiceModel.Id = invoice.Id;
                invoiceModel.ClientId = invoice.ClientId;
                invoiceModel.Notes = invoice.Notes;
                invoiceModel.MeetingId = invoice.MeetingId;
                invoiceModel.Number = invoice.Number;

                return new ReturnModel<InvoiceModel>
                {
                    Status = true,
                    Result = invoiceModel
                };
            };
        }
开发者ID:mberaz,项目名称:foodMenu,代码行数:22,代码来源:InvoiceBL.cs


注:本文中的UnitOfWork.GetRepository方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。