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


C# UnitOfWork.SaveChanges方法代码示例

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


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

示例1: AddDeleteStoryById

        public void AddDeleteStoryById()
        {
            using (IDataContextAsync myStoriesFakeContext = new MyStoriesFakeContext())
            using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(myStoriesFakeContext))
            {

                var groups = new List<Group>
                {
                    new Group {Id = 1, Name = "Group1", Description = "Group Desc", ObjectState = ObjectState.Added},
                    new Group {Id = 2, Name = "Group2", Description = "Group Desc", ObjectState = ObjectState.Added}
                };

                foreach (var g in groups)
                {
                    unitOfWork.Repository<Group>().Insert(g);
                }

                unitOfWork.Repository<Story>().Insert(new Story {Id = 1, Description = "Desc", Content = "Content", Title = "Title", PostedOn = DateTime.Today, Groups = groups});

                unitOfWork.SaveChanges();

                unitOfWork.Repository<Story>().Delete(1);

                unitOfWork.SaveChanges();

                var story = unitOfWork.Repository<Story>().Find(1);

                Assert.IsNull(story);
            }
        }
开发者ID:arkirakosyan,项目名称:MyStories,代码行数:30,代码来源:StoryRepositoryTest.cs

示例2: Create

        //Create redeemed Count
        public static int Create(RedeemedCountDTO RedeemedCountDTO)
        {
            try
            {
                var RedeemedCount = new RedeemedCount();

                GlobalSettings.LoggedInClientId = RedeemedCountDTO.ClientId;
                GlobalSettings.LoggedInUserId = RedeemedCountDTO.UserId;
                int PartnerId = ClientService.GetById(RedeemedCountDTO.ClientId).PartnerId;
                GlobalSettings.LoggedInPartnerId = PartnerId;

                UnitOfWork uow = new UnitOfWork();
                RedeemedCount = Transform.RedeemedCountToDomain(RedeemedCountDTO);
                uow.RedeemedCountRepo.Insert(RedeemedCount);

                uow.SaveChanges();
                RedeemedCount.Id = RedeemedCount.Id;
                return RedeemedCount.Id;

            }

            catch (Exception)
            {
                throw;
            }
        }
开发者ID:Prasadambulkar3,项目名称:msgBlaster-api,代码行数:27,代码来源:RedeemedCountService.cs

示例3: Delete

        //Delete location by id
        public static bool Delete(int Id)
        {
            GlobalSettings.LoggedInClientId = LocationService.GetById(Id).ClientId;
            int PartnerId = ClientService.GetById(Convert.ToInt32( GlobalSettings.LoggedInClientId)).PartnerId;
            GlobalSettings.LoggedInPartnerId = PartnerId;

            bool IsExists = IsChildEntityExist(Id);
            try
            {
                if (IsExists != true)
                {
                    LocationDTO LocationDTO = new LocationDTO();
                    LocationDTO = GetById(Id);
                    UnitOfWork uow = new UnitOfWork();
                    uow.LocationRepo.Delete(Id);
                    uow.SaveChanges();
                    return true;
                }
                else return false;
            }
            catch
            {
                throw;
            }
        }
开发者ID:Prasadambulkar3,项目名称:msgBlaster-api,代码行数:26,代码来源:LocationService.cs

示例4: Create

        //Create Contact
        public static int Create(ContactDTO ContactDTO)
        {
            try
            {
                GlobalSettings.LoggedInClientId = ContactDTO.ClientId;
                int PartnerId = ClientService.GetById(ContactDTO.ClientId).PartnerId;
                GlobalSettings.LoggedInPartnerId = PartnerId;

                var contact = new Contact();
                using (var uow = new UnitOfWork())
                {
                    contact = Transform.ContactToDomain(ContactDTO);

                    uow.ContactRepo.Insert(contact);
                    uow.SaveChanges();
                    if (ContactDTO.Groups != null)
                    {
                        foreach (var item in ContactDTO.Groups)
                        {
                            AddGroupToContact(contact.Id, item.Id);
                        }
                    }
                    return (contact.Id);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
开发者ID:Prasadambulkar3,项目名称:msgBlaster-api,代码行数:31,代码来源:ContactService.cs

示例5: Create

        //Create location
        public static int Create(LocationDTO LocationDTO)
        {
            try
            {
                GlobalSettings.LoggedInClientId = LocationDTO.ClientId;
                int PartnerId = ClientService.GetById(LocationDTO.ClientId).PartnerId;
                GlobalSettings.LoggedInPartnerId = PartnerId;

                var Location = new Location();

                UnitOfWork uow = new UnitOfWork();
                Location = Transform.LocationToDomain(LocationDTO);
                uow.LocationRepo.Insert(Location);

                uow.SaveChanges();
                Location.Id = Location.Id;
                return Location.Id;

            }

            catch (Exception)
            {
                throw;
            }
        }
开发者ID:Prasadambulkar3,项目名称:msgBlaster-api,代码行数:26,代码来源:LocationService.cs

示例6: Create

        //Create template
        public static int Create(TemplateDTO TemplateDTO)
        {
            if (TemplateDTO.Title == null || TemplateDTO.Title == "") { return 0; }

            try
            {
                var Template = new Template();

                GlobalSettings.LoggedInClientId = TemplateDTO.ClientId;
                int PartnerId = ClientService.GetById(TemplateDTO.ClientId).PartnerId;
                GlobalSettings.LoggedInPartnerId = PartnerId;

                UnitOfWork uow = new UnitOfWork();
                Template = Transform.TemplateToDomain(TemplateDTO);
                uow.TemplateRepo.Insert(Template);

                uow.SaveChanges();
                TemplateDTO.Id = Template.Id;
                return TemplateDTO.Id;

            }

            catch (Exception)
            {
                throw;
            }
        }
开发者ID:Prasadambulkar3,项目名称:msgBlaster-api,代码行数:28,代码来源:TemplateService.cs

示例7: CreateUser

        private static bool CreateUser()
        {
            var user = BuildNewUser();

            using (IDataContextAsync ctx = new AppDataContext())
            using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(ctx))
            {
                IRepositoryAsync<User> userRepository = new Repository<User>(ctx,
                    unitOfWork);

                userRepository.InsertOrUpdateGraph(user);
                try
                {
                    unitOfWork.SaveChanges();
                }
                catch (Exception e)
                {
                    Console.WriteLine();
                    Console.WriteLine(e);
                    return false;
                }

                return true;
            }
        }
开发者ID:Neilski,项目名称:URF-TestApp,代码行数:25,代码来源:Program.cs

示例8: CompleteComputingTask

        public void CompleteComputingTask(Guid asynTaskID, Guid userID,
            int totalComputed, int totalProfile, DataErrorCode dataErrorCode)
        {
            #region Lưu Sys_AsynTask khi xử lý xong

            if (asynTaskID != Guid.Empty)
            {
                using (var taskContext = new VnrHrmDataContext())
                {
                    IUnitOfWork taskunitOfWork = new UnitOfWork(taskContext);
                    var asynTask = taskunitOfWork.CreateQueryable<Sys_AsynTask>(s => s.ID == asynTaskID).FirstOrDefault();

                    if (asynTask != null)
                    {
                        asynTask.PercentComplete = 1D;
                        asynTask.TimeEnd = DateTime.Now;
                        asynTask.Status = AsynTaskStatus.Done.ToString();

                        var time = asynTask.TimeEnd.Value.Subtract(asynTask.TimeStart).TotalMinutes;
                        asynTask.Description += " - Result: " + totalComputed + "/" + totalProfile;
                        asynTask.Description += " - Time: " + time.ToString("N2");

                        if (dataErrorCode == DataErrorCode.Locked)
                        {
                            asynTask.PercentComplete = 1D;//Không cần nhân với 100
                            asynTask.Description = "Dữ Liệu Quẹt Thẻ Đã Bị Khóa";
                        }

                        dataErrorCode = taskunitOfWork.SaveChanges();
                    }
                }
            }

            #endregion
        }
开发者ID:dtafe,项目名称:vnr,代码行数:35,代码来源:Can_TamServices.cs

示例9: DeleteByGroupId

        //Delete group contact by group id and contact id
        public static bool DeleteByGroupId(int GroupId, int ContactId)
        {
            try
            {

                GroupContactDTO GroupContactDTO = new GroupContactDTO();
                UnitOfWork uow = new UnitOfWork();
                IEnumerable<GroupContact> GroupContact = uow.GroupContactRepo.GetAll().Where(e => e.GroupId == GroupId && e.ContactId == ContactId);
                if (GroupContact != null)
                {
                    foreach (var item in GroupContact)
                    {
                        //GroupContactDTO = GetById(item.Id);
                        uow.GroupContactRepo.Delete(item.Id);
                        uow.SaveChanges();
                    }
                }
                return true;
            }
            catch
            {

                throw;
            }
        }
开发者ID:Prasadambulkar3,项目名称:msgBlaster-api,代码行数:26,代码来源:GroupContactService.cs

示例10: AddProducts

        public void AddProducts()
        {
            for (var x = 0; x < 2; x++)
            {
                var products = new List<Product>();

                for (var i = 0; i < 100; i++)
                {
                    products.Add(new Product
                    {
                        ProductName = Guid.NewGuid().ToString(),
                        Discontinued = false,
                        ObjectState = ObjectState.Added
                    });
                }

                using (IDataContextAsync context = new NorthwindContext())
                using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context))
                {
                    var northwindContext = (NorthwindContext)context;
                    Assert.IsFalse(northwindContext.ChangeTracker.Entries().Any());

                    IRepositoryAsync<Product> productRepository =
                        new Repository<Product>(context, unitOfWork);

                    productRepository.InsertGraphRange(products);
                    products.Clear();
                    unitOfWork.SaveChanges();

                    Assert.IsTrue(northwindContext.ChangeTracker.Entries().Count() == 100);
                }

                System.Threading.Thread.Sleep(5000);
            }
        }
开发者ID:vorba,项目名称:purevision4,代码行数:35,代码来源:ChangeTrackerEntries.cs

示例11: CancelCampaign

        //Edit Campaign
        public static void CancelCampaign(CampaignDTO campaignDTO)
        {
            try
            {
                UnitOfWork uow = new UnitOfWork();

                //Add Consumed Credits to clients
                ClientDTO ClientDTO = new ClientDTO();
                ClientDTO = ClientService.GetById(campaignDTO.ClientId);
                ClientDTO.SMSCredit = ClientDTO.SMSCredit + campaignDTO.ConsumedCredits;
                ClientService.Edit(ClientDTO);

                campaignDTO.ConsumedCredits = 0;
                campaignDTO.Status = "Cancelled";
                CampaignService.Edit(campaignDTO);

                Campaign Campaign = Transform.CampaignToDomain(campaignDTO);
                uow.CampaignRepo.Update(Campaign);
                uow.SaveChanges();
            }
            catch
            {
                throw;
            }
        }
开发者ID:Prasadambulkar3,项目名称:msgBlaster-api,代码行数:26,代码来源:CampaignService.cs

示例12: Create

        //Create group
        public static int Create(GroupDTO GroupDTO)
        {
            try
            {

                GlobalSettings.LoggedInClientId = GroupDTO.ClientID;
                int PartnerId = ClientService.GetById(GroupDTO.ClientID).PartnerId;
                GlobalSettings.LoggedInPartnerId = PartnerId;

                var group = new Group();

                UnitOfWork uow = new UnitOfWork();
                GroupDTO.ClientID = GroupDTO.ClientID;
                group = Transform.GroupToDomain(GroupDTO);
                uow.GroupRepo.Insert(group);

                uow.SaveChanges();

                GroupDTO.Id = group.Id;
                return GroupDTO.Id;

            }

            catch (Exception)
            {
                throw;
            }
        }
开发者ID:Prasadambulkar3,项目名称:msgBlaster-api,代码行数:29,代码来源:GroupService.cs

示例13: Delete

        //Delete document by id and file path
        public static bool Delete(int Id, string FilePath)
        {
            bool IsDeleted = false;
            try
            {

                DocumentDTO DocumentDTO = new DocumentDTO();
                DocumentDTO = GetById(Id);
                GlobalSettings.LoggedInClientId = DocumentDTO.ClientId;
                GlobalSettings.LoggedInUserId = DocumentDTO.UserId;
                int PartnerId = ClientService.GetById(DocumentDTO.ClientId).PartnerId;
                GlobalSettings.LoggedInPartnerId = PartnerId;

                IsDeleted = CommonService.RemoveDocument(FilePath); //+ DocumentDTO.Path
                if (IsDeleted != false)
                {
                    UnitOfWork uow = new UnitOfWork();
                    uow.DocumentRepo.Delete(Id);
                    uow.SaveChanges();
                }
                return IsDeleted;
            }
            catch
            {
                throw;
            }
        }
开发者ID:Prasadambulkar3,项目名称:msgBlaster-api,代码行数:28,代码来源:DocumentService.cs

示例14: Create

        //Create document
        public static int Create(DocumentDTO DocumentDTO)
        {
            try
            {
                GlobalSettings.LoggedInClientId = DocumentDTO.ClientId;
                GlobalSettings.LoggedInUserId = DocumentDTO.UserId;
                int PartnerId = ClientService.GetById(DocumentDTO.ClientId).PartnerId;
                GlobalSettings.LoggedInPartnerId = PartnerId;

                var Document = new Document();
                using (var uow = new UnitOfWork())
                {
                    Document = Transform.DocumentToDomain(DocumentDTO);
                    uow.DocumentRepo.Insert(Document);
                    uow.SaveChanges();
                    return (Document.Id);

                }

            }
            //catch (LoggedInUserException)
            //{
            //    throw new System.TimeoutException();
            //}
            catch (Exception)
            {
                throw;
            }
        }
开发者ID:Prasadambulkar3,项目名称:msgBlaster-api,代码行数:30,代码来源:DocumentService.cs

示例15: AddCustomerTest

        public void AddCustomerTest()
        {
            using(var dataContext = new ModelDataContext())
            using (var unitOfWork = new UnitOfWork(dataContext) )
            {
                var customerID = Guid.NewGuid();

                var customer = new Customer()
                {
                     ID = Guid.NewGuid(),
                     Name = "BBC",
                     Address = "No.1 Bee Street",
                     City = "London",
                     Country = "UK",
                     Region = "AA",
                     Fax = "000000",
                     Phone = "00000000000",
                     PostalCode = "555555"
                };

                var customerRepository = unitOfWork.Repository<Customer>();

                customerRepository.Insert(customer); ;
                unitOfWork.SaveChanges();

                var insertedCustomer = customerRepository.Find(customerID);

                Assert.IsNotNull(insertedCustomer);
                Assert.AreEqual(customerID, insertedCustomer.ID);
            }
        }
开发者ID:kaleyroy,项目名称:TrainingRecipes,代码行数:31,代码来源:CustomerRepositoryTest.cs


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