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


C# IUnitOfWork.SaveChanges方法代码示例

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


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

示例1: WorkflowUserService

        public WorkflowUserService(
            IUnitOfWork unitOfWork)
        {

            if (_manager == null)
            {
                var repository = unitOfWork.GetRepository<User>();

                var user = repository.Find(x => x.Login == "WorkflowManager");
                if (user == null)
                {
                    user = new User
                    {
                        Login = "WorkflowManager",
                        CategoryID = 1,
                        Roles = new List<Role> {
                            new Role {
                                ChildRoles = new List<ChildRole>(),
                                Permissions = new List<Permission>(),
                                Name = "WorkflowManagerRole",
                                SystemRole = SystemRole.Admin
                            }
                        },
                        FirstName = "Менеджер бизнес-процессов"
                    };

                    repository.Create(user);
                    unitOfWork.SaveChanges();
                }

                _manager = new SecurityUser(user);
            }
        }
开发者ID:altaricka,项目名称:vDesign,代码行数:33,代码来源:WorkflowUserService.cs

示例2: AddToCart

        public int AddToCart(IUnitOfWork unitOfWork, ICartService cartService, Product product)
        {
            var cartItem = cartService.ODataQueryable().SingleOrDefault(
                    c => c.CartId == ShoppingCartId
                    && c.ProductId == product.Id);

            if (cartItem == null)
            {
                cartItem = new Cart
                {
                    CartId = ShoppingCartId,
                    ProductId = product.Id,
                    Count = 1,
                    DateCreated = DateTime.Now
                };
                cartService.Insert(cartItem);
            }
            else
            {
                cartItem.Count++;
                cartService.Update(cartItem);
            }

            //save changes
            unitOfWork.SaveChanges();
            return cartItem.Count;
        }
开发者ID:thuyhk,项目名称:ThuanThienVN,代码行数:27,代码来源:ShoppingCart.cs

示例3: Create

        public UnregisteredUser Create(IUnitOfWork unitOfWork, UnregisteredUser obj)
        {
            obj.Email = obj.Email.Trim();

            var repository = unitOfWork.GetRepository<User>();

            if (repository.All().Any(x => x.Email.Equals(obj.Email, StringComparison.InvariantCultureIgnoreCase)))
            {
                throw new Exception("Пользователь с таким адресом электронной почты уже существует. Вы можете найти данный контакт через поиск.");
            }

            var catRepo = unitOfWork.GetRepository<UserCategory>();

            var cat = catRepo.All().FirstOrDefault(x => x.SystemName == "Unregistered") ?? new UserCategory
            {
                Name = "Незарегистрированные пользователи",
                SystemName = "Unregistered"
            };

            var user = new User
            {
                Login = obj.Email,
                FirstName = obj.FirstName,
                LastName = obj.LastName,
                MiddleName = obj.MiddleName,
                Email = obj.Email,
                OfficePhone = obj.OfficePhone,
                PersonPhone = obj.PersonPhone,
                MailAddress = obj.MailAddress,
                UserCategory = cat,
                IsUnregistered = true
            };

            repository.Create(user);

            unitOfWork.SaveChanges();

            obj.ID = user.ID;

            return obj;
        }
开发者ID:altaricka,项目名称:vDesign,代码行数:41,代码来源:UnregisteredUserService.cs

示例4: Delete

        public virtual void Delete(IUnitOfWork unitOfWork, ObjectAccessItem obj)
        {
            var repository = unitOfWork.GetRepository<ObjectAccessItem>();

            obj.Hidden = true;

            repository.Update(obj);

            unitOfWork.SaveChanges();

            var eventHandler = Volatile.Read(ref this.OnDelete);

            if (eventHandler != null)
            {
                eventHandler(this, new BaseObjectEventArgs()
                {
                    Type = TypeEvent.OnDelete,
                    Object = obj,
                    UnitOfWork = unitOfWork
                });
            }
        }
开发者ID:altaricka,项目名称:vDesign,代码行数:22,代码来源:ObjectAccessItemService.cs

示例5: DeleteUsersPostsPollsVotesAndPoints

        private void DeleteUsersPostsPollsVotesAndPoints(MembershipUser user, IUnitOfWork unitOfWork)
        {
            // Delete all file uploads
            var files = _uploadedFileService.GetAllByUser(user.Id);
            var filesList = new List<UploadedFile>();
            filesList.AddRange(files);
            foreach (var file in filesList)
            {
                // store the file path as we'll need it to delete on the file system
                var filePath = file.FilePath;

                // Now delete it
                _uploadedFileService.Delete(file);

                // And finally delete from the file system
                System.IO.File.Delete(Server.MapPath(filePath));
            }

            // Delete all posts
            var posts = user.Posts;
            var postList = new List<Post>();
            postList.AddRange(posts);
            foreach (var post in postList)
            {
                post.Files.Clear();
                _postService.Delete(post);
            }

            unitOfWork.SaveChanges();

            // Also clear their poll votes
            var userPollVotes = user.PollVotes;
            if (userPollVotes.Any())
            {
                var pollList = new List<PollVote>();
                pollList.AddRange(userPollVotes);
                foreach (var vote in pollList)
                {
                    vote.User = null;
                    _pollVoteService.Delete(vote);
                }
                user.PollVotes.Clear();
            }

            unitOfWork.SaveChanges();

            // Also clear their polls
            var userPolls = user.Polls;
            if (userPolls.Any())
            {
                var polls = new List<Poll>();
                polls.AddRange(userPolls);
                foreach (var poll in polls)
                {
                    //Delete the poll answers
                    var pollAnswers = poll.PollAnswers;
                    if (pollAnswers.Any())
                    {
                        var pollAnswersList = new List<PollAnswer>();
                        pollAnswersList.AddRange(pollAnswers);
                        foreach (var answer in pollAnswersList)
                        {
                            answer.Poll = null;
                            _pollAnswerService.Delete(answer);
                        }
                    }

                    poll.PollAnswers.Clear();
                    poll.User = null;
                    _pollService.Delete(poll);
                }
                user.Polls.Clear();
            }

            unitOfWork.SaveChanges();

            // Delete all topics
            var topics = user.Topics;
            var topicList = new List<Topic>();
            topicList.AddRange(topics);
            foreach (var topic in topicList)
            {
                _topicService.Delete(topic);
            }

            // Also clear their points
            var userPoints = user.Points;
            if (userPoints.Any())
            {
                var pointsList = new List<MembershipUserPoints>();
                pointsList.AddRange(userPoints);
                foreach (var point in pointsList)
                {
                    point.User = null;
                    _membershipUserPointsService.Delete(point);
                }
                user.Points.Clear();
            }

            unitOfWork.SaveChanges();
//.........这里部分代码省略.........
开发者ID:kangjh0815,项目名称:test,代码行数:101,代码来源:AccountController.cs

示例6: UpdateProduct

        private static void UpdateProduct(IUnitOfWork uow)
        {
            Console.WriteLine("Update Product!");
            Console.WriteLine("---------------");
            Console.WriteLine();

            Console.Write("Please, enter the id of product you want to update: ");
            var productId = int.Parse(Console.ReadLine());

            var product = uow.ProductRepository.GetById(productId);

            Console.WriteLine();
            Console.Write("Please, enter the new name of the product you want to update: ");
            var productName = Console.ReadLine();

            product.Name = productName;

            uow.ProductRepository.Update(product);
            uow.SaveChanges();

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Product successfully updated.");
            Console.ForegroundColor = ConsoleColor.Gray;
        }
开发者ID:edm35,项目名称:SimpleDAO,代码行数:24,代码来源:Program.cs

示例7: Delete

        /// <summary>
        /// Delete a topic
        /// </summary>
        /// <param name="topic"></param>
        /// <param name="unitOfWork"></param>
        public void Delete(Topic topic, IUnitOfWork unitOfWork)
        {
            // First thing - Set the last post as null and clear tags
            topic.LastPost = null;
            topic.Tags.Clear();

            // Save here to clear the last post
            unitOfWork.SaveChanges();

            // TODO - Need to refactor as some of the code below is duplicated in the post delete

            // Loop through all the posts and clear the associated entities
            // then delete the posts
            if (topic.Posts != null)
            {
                var postsToDelete = new List<Post>();
                postsToDelete.AddRange(topic.Posts);
                foreach (var post in postsToDelete)
                {
                    // Posts should only be deleted from this method as it clears
                    // associated data
                    _postService.Delete(post, unitOfWork, true);
                }

                // Final clear
                topic.Posts.Clear();
            }

            unitOfWork.SaveChanges();

            // Remove all notifications on this topic too
            if (topic.TopicNotifications != null)
            {
                var notificationsToDelete = new List<TopicNotification>();
                notificationsToDelete.AddRange(topic.TopicNotifications);
                foreach (var topicNotification in notificationsToDelete)
                {
                    _topicNotificationService.Delete(topicNotification);
                }

                // Final Clear
                topic.TopicNotifications.Clear();
            }

            // Remove all favourites on this topic too
            if (topic.Favourites != null)
            {
                var toDelete = new List<Favourite>();
                toDelete.AddRange(topic.Favourites);
                foreach (var entity in toDelete)
                {
                    _favouriteService.Delete(entity);
                }

                // Final Clear
                topic.Favourites.Clear();
            }

            // Poll
            if (topic.Poll != null)
            {
                //Delete the poll answers
                var pollAnswers = topic.Poll.PollAnswers;
                if (pollAnswers.Any())
                {
                    var pollAnswersList = new List<PollAnswer>();
                    pollAnswersList.AddRange(pollAnswers);
                    foreach (var answer in pollAnswersList)
                    {
                        answer.Poll = null;
                        _pollAnswerService.Delete(answer);
                    }
                }

                topic.Poll.PollAnswers.Clear();
                topic.Poll.User = null;
                _pollService.Delete(topic.Poll);

                // Final Clear
                topic.Poll = null;
            }

            // Finally delete the topic
            _context.Topic.Remove(topic);
        }
开发者ID:ivanchen52,项目名称:mvcforum,代码行数:90,代码来源:TopicService.cs

示例8: UpdateCollection

        private static void UpdateCollection(IUnitOfWork uow)
        {
            Console.WriteLine("Update Collection!");
            Console.WriteLine("------------------");
            Console.WriteLine();

            Console.Write("Please, enter the id of collection you want to update: ");
            var collectionId = int.Parse(Console.ReadLine());

            var collection = uow.CollectionRepository.GetById(collectionId);

            Console.WriteLine();
            Console.Write("Please, enter the new name of the collection you want to update: ");
            var collectionName = Console.ReadLine();

            collection.Name = collectionName;

            uow.CollectionRepository.Update(collection);
            uow.SaveChanges();

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Collection successfully updated.");
            Console.ForegroundColor = ConsoleColor.Gray;
        }
开发者ID:edm35,项目名称:SimpleDAO,代码行数:24,代码来源:Program.cs

示例9: DeleteProduct

        private static void DeleteProduct(IUnitOfWork uow)
        {
            Console.WriteLine("Delete Product!");
            Console.WriteLine("------------------");
            Console.WriteLine();

            Console.Write("Please, enter the id of product you want to delete: ");
            var productId = int.Parse(Console.ReadLine());

            var product = uow.ProductRepository.GetById(productId);

            uow.ProductRepository.Remove(product);
            uow.SaveChanges();

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Product successfully deleted.");
            Console.ForegroundColor = ConsoleColor.Gray;
        }
开发者ID:edm35,项目名称:SimpleDAO,代码行数:18,代码来源:Program.cs

示例10: ProcessFirstBackOff

        private void ProcessFirstBackOff(
            Pmta pmta,
            string queue,
            IUnitOfWork unitOfWork,
            IEventRepository eventRepository
            )
        {
            _logger.InfoFormat("First Back Off for {0} on {1}", queue, pmta.Host);

            Event dbLogEvent = eventRepository.Add(new Event()
                                                   {
                                                       EventName = Event.EventNames.FirstBackOff,
                                                       Monitor = Event.Monitors.Four21,
                                                       SeriesId = Guid.NewGuid()
                                                   });

            _mtaAgent.RemoveBackoff(pmta.ToMta(), queue);
            _logger.InfoFormat("Removed Back Off from {0} on {1}", queue, pmta.Host);

            dbLogEvent.EventActions.Add(new EventAction()
                                            {
                                                Action = EventAction.Actions.RemoveBackOff,
                                                Pmta = pmta,
                                                PmtaQueue = queue
                                            });

            lock (_locker)
            {
                unitOfWork.SaveChanges();
            }
        }
开发者ID:c0d3m0nky,项目名称:mty,代码行数:31,代码来源:Four21.cs

示例11: DeleteCollection

        private static void DeleteCollection(IUnitOfWork uow)
        {
            Console.WriteLine("Delete Collection!");
            Console.WriteLine("------------------");
            Console.WriteLine();

            Console.Write("Please, enter the id of collection you want to delete: ");
            var collectionId = int.Parse(Console.ReadLine());

            var collection = uow.CollectionRepository.GetById(collectionId);

            uow.CollectionRepository.Remove(collection);
            uow.SaveChanges();

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Collection successfully deleted.");
            Console.ForegroundColor = ConsoleColor.Gray;
        }
开发者ID:edm35,项目名称:SimpleDAO,代码行数:18,代码来源:Program.cs

示例12: ResumeSecondBackOff

        private void ResumeSecondBackOff(
            Event secondEventInstance,
            IUnitOfWork unitOfWork,
            IJobRepository jobRepository,
            IEventRepository eventRepository,
            IDeliveryGroupRepository deliveryGroupRepository,
            Event currentEvent = null
            )
        {
            var eventDetail = secondEventInstance.EventActions.FirstOrDefault(ed => ed.Action == EventAction.Actions.MTAPause);

            if (eventDetail != null && !_mtaAgent.IsQueueActive(eventDetail.Pmta.ToMta(), eventDetail.PmtaQueue))
            {
                _logger.InfoFormat("Resuming {0} on {1}", eventDetail.PmtaQueue, eventDetail.Pmta.Host);

                Event dbLogEvent = currentEvent ?? eventRepository.Add(new Event()
                                                       {
                                                           EventName = Event.EventNames.SecondBackOffResume,
                                                           Monitor = Event.Monitors.Four21,
                                                           SeriesId = secondEventInstance.SeriesId
                                                       });

                _mtaAgent.Purge(eventDetail.Pmta.ToMta(), eventDetail.PmtaQueue);
                _logger.InfoFormat("Purged {0} on {1}", eventDetail.PmtaQueue, eventDetail.Pmta.Host);

                dbLogEvent.EventActions.Add(new EventAction()
                        {
                            Action = EventAction.Actions.MTAPurge,
                            Pmta = eventDetail.Pmta,
                            PmtaQueue = eventDetail.PmtaQueue
                        });

                _mtaAgent.UnPause(eventDetail.Pmta.ToMta(), eventDetail.PmtaQueue);
                _logger.InfoFormat("Resumed {0} on {1}", eventDetail.PmtaQueue, eventDetail.Pmta.Host);

                dbLogEvent.EventActions.Add(new EventAction()
                {
                    Action = EventAction.Actions.ResumedQueue,
                    Pmta = eventDetail.Pmta,
                    PmtaQueue = eventDetail.PmtaQueue
                });

                lock (_locker)
                {
                    unitOfWork.SaveChanges();
                }
            }
        }
开发者ID:c0d3m0nky,项目名称:mty,代码行数:48,代码来源:Four21.cs

示例13: ProcessSecondBackOff

        private void ProcessSecondBackOff(
            Pmta pmta,
            string queue,
            Event lastEvent,
            IUnitOfWork unitOfWork,
            IEventRepository eventRepository
            )
        {
            _logger.InfoFormat("Second Back Off for {0} on {1}", queue, pmta.Host);

            Event dbLogEvent = eventRepository.Add(new Event()
                                                   {
                                                       EventName = Event.EventNames.SecondBackOff,
                                                       Monitor = Event.Monitors.Four21,
                                                       SeriesId = lastEvent.SeriesId
                                                   });

            _mtaAgent.Pause(pmta.ToMta(), queue);
            _logger.InfoFormat("Paused {0} on {1}", queue, pmta.Host);

            dbLogEvent.EventActions.Add(new EventAction()
                {
                    Action = EventAction.Actions.MTAPause,
                    Pmta = pmta,
                    PmtaQueue = queue
                });

            _mtaAgent.RemoveBackoff(pmta.ToMta(), queue);
            _logger.InfoFormat("Removed Back Off from {0} on {1}", queue, pmta.Host);

            dbLogEvent.EventActions.Add(new EventAction()
                {
                    Action = EventAction.Actions.RemoveBackOff,
                    Pmta = pmta,
                    PmtaQueue = queue
                });

            _mtaAgent.Purge(pmta.ToMta(), queue);
            _logger.InfoFormat("Purged {0} on {1}", queue, pmta.Host);

            dbLogEvent.EventActions.Add(new EventAction()
            {
                Action = EventAction.Actions.MTAPurge,
                Pmta = pmta,
                PmtaQueue = queue
            });

            lock (_locker)
            {
                unitOfWork.SaveChanges();
            }
        }
开发者ID:c0d3m0nky,项目名称:mty,代码行数:52,代码来源:Four21.cs

示例14: ProcessFourthBackOff

        private void ProcessFourthBackOff(
            Pmta pmta,
            string queue,
            Event lastEvent,
            DateTime nextReset,
            IUnitOfWork unitOfWork,
            IJobRepository jobRepository,
            IEventRepository eventRepository,
            IDeliveryGroupRepository deliveryGroupRepository
            )
        {
            _logger.InfoFormat("Fourth Back Off for {0} on {1}", queue, pmta.Host);

            var dbLogEvent = eventRepository.Add(new Event()
            {
                EventName = Event.EventNames.FourthBackOff,
                Monitor = Event.Monitors.Four21,
                SeriesId = lastEvent.SeriesId
            });

            _mtaAgent.Pause(pmta.ToMta(), queue);
            _logger.InfoFormat("Paused {0} on {1}", queue, pmta.Host);

            dbLogEvent.EventActions.Add(new EventAction()
                {
                    Action = EventAction.Actions.MTAPause,
                    Pmta = pmta,
                    PmtaQueue = queue
                });

            _mtaAgent.RemoveBackoff(pmta.ToMta(), queue);
            _logger.InfoFormat("Removed Back Off from {0} on {1}", queue, pmta.Host);

            dbLogEvent.EventActions.Add(new EventAction()
                {
                    Action = EventAction.Actions.RemoveBackOff,
                    Pmta = pmta,
                    PmtaQueue = queue
                });

            _mtaAgent.Purge(pmta.ToMta(), queue);
            _logger.InfoFormat("Purged {0} on {1}", queue, pmta.Host);

            dbLogEvent.EventActions.Add(new EventAction()
            {
                Action = EventAction.Actions.MTAPurge,
                Pmta = pmta,
                PmtaQueue = queue
            });

            lock (_locker)
            {
                var deliveryGroup = DeliveryGroup.GetByVmta(pmta, queue, deliveryGroupRepository);

                if (deliveryGroup != null)
                {
                    DeliveryGroup.CancelHotmailJobsByDeliveryGroup(jobRepository, _logger, deliveryGroup, nextReset, dbLogEvent);
                }

                unitOfWork.SaveChanges();
            }

            _emailNotification.SendEvent(dbLogEvent);

        }
开发者ID:c0d3m0nky,项目名称:mty,代码行数:65,代码来源:Four21.cs

示例15: ProcessPmta

        private void ProcessPmta(
            Pmta pmta,
            DateTime nextReset,
            IUnitOfWork unitOfWork,
            IJobRepository jobRepository,
            IEventRepository eventRepository,
            IDeliveryGroupRepository deliveryGroupRepository
            )
        {

            foreach (var queue in _mtaAgent.GetVmtasIn421BackoffMode(pmta.ToMta()))
            {
                Event lastEvent = null;

                lock (_locker)
                {
                    lastEvent = Event.GetLastQueueEvent(eventRepository, Event.Monitors.Four21, pmta, queue);
                }

                if (lastEvent != null && lastEvent.DateCreated.AddHours(1) >= DateTime.Now)
                {
                    switch (lastEvent.EventName)
                    {
                        case Event.EventNames.FirstBackOff:
                            ProcessSecondBackOff(pmta, queue, lastEvent, unitOfWork, eventRepository);
                            break;
                        case Event.EventNames.SecondBackOff:
                        case Event.EventNames.SecondBackOffResume:
                            ProcessThirdBackOff(pmta, queue, lastEvent, unitOfWork, eventRepository);
                            break;
                        case Event.EventNames.ThirdBackOff:
                            ProcessFourthBackOff(pmta, queue, lastEvent, nextReset, unitOfWork, jobRepository, eventRepository, deliveryGroupRepository);
                            break;
                        default:
                            ProcessFirstBackOff(pmta, queue, unitOfWork, eventRepository);
                            break;
                    }
                }
                else
                {
                    ProcessFirstBackOff(pmta, queue, unitOfWork, eventRepository);
                }
            }

            IEnumerable<Event> events = null;

            lock (_locker)
            {
                events = Event.Get421QueueResumeEvents(eventRepository).ToArray();
            }

            events.ToList().ForEach(e => ResumeSecondBackOff(e, unitOfWork, jobRepository, eventRepository, deliveryGroupRepository));

            unitOfWork.SaveChanges();

        }
开发者ID:c0d3m0nky,项目名称:mty,代码行数:56,代码来源:Four21.cs


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