コード例 #1
0
        public async Task <BoolResult> Delete(Circle circle)
        {
            var dbUser = DbUser;

            using (var transactionScope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
                using (CircleRepository _circleRepostiRepository = new CircleRepository(Context, dbUser, null))
                {
                    try
                    {
                        var circleItem = _circleRepostiRepository.GetById(circle.Id);
                        if (circleItem == null)
                        {
                            return(new BoolResult()
                            {
                                IsOk = false,
                                ErrorMessage = "No circle info"
                            });
                        }
                        _circleRepostiRepository.Delete(circleItem);
                        Context.SaveChanges();
                        transactionScope.Complete();
                        return(new BoolResult()
                        {
                            IsOk = true
                        });
                    }
                    catch (Exception e)
                    {
                        LogHelper.WriteError(e);
                        return(new BoolResult()
                        {
                            IsOk = false,
                            ErrorMessage = e.ToString()
                        });
                    }
                }
        }
コード例 #2
0
        public async Task <IdResult> Submit(Circle circle)
        {
            if (circle == null)
            {
                return(new IdResult()
                {
                    IsOk = false,
                    ErrorMessage = "No circle info"
                });
            }
            if (circle.SelectedContacts == null)
            {
                return(new IdResult()
                {
                    IsOk = false,
                    ErrorMessage = "Circle can not be empty"
                });
            }

            Common.Model.Circle circleItem = null;
            var dbUser = DbUser;

            using (var transactionScope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
                using (CircleRepository _circleRepostiRepository = new CircleRepository(Context, dbUser, null))
                {
                    {
                        try
                        {
                            if (circle.Id == Guid.Empty)
                            {
                                circleItem = new Common.Model.Circle()
                                {
                                    Name    = circle.Name,
                                    IsGroup = true,
                                };
                                _circleRepostiRepository.Create(circleItem);
                                Context.SaveChanges();
                                _circleRepostiRepository.AddMainPersonToCircleUser(circleItem.Id, dbUser);
                            }
                            else
                            {
                                circleItem      = _circleRepostiRepository.GetById(circle.Id);
                                circleItem.Name = circle.Name;
                                _circleRepostiRepository.Update(circleItem);
                            }

                            var selectedContacts = circle.SelectedContacts.Select(p => p.Id).ToList();
                            _circleRepostiRepository.SynchCircleUsers(circleItem.Id, selectedContacts, circle.Name, dbUser);
                            Context.SaveChanges();
                            transactionScope.Complete();
                            return(new IdResult()
                            {
                                IsOk = true,
                                Id = circleItem.Id
                            });
                        }
                        catch (Exception e)
                        {
                            LogHelper.WriteError(e);
                            return(new IdResult()
                            {
                                IsOk = false,
                                ErrorMessage = e.ToString()
                            });
                        }
                    }
                }
        }