예제 #1
0
        public ActionResult CreateFromPeanut(Peanut peanut, User currentUser)
        {
            Require.NotNull(currentUser, "currentUser");
            Require.NotNull(peanut, "peanut");

            UserGroupMembership         currentUsersMembershipsInPeanutGroup = UserGroupService.FindMembershipsByUserAndGroup(currentUser, peanut.UserGroup);
            IList <UserGroupMembership> availableUserGroupMemberships        =
                UserGroupService.FindMembershipsByGroups(PageRequest.All,
                                                         new List <UserGroup> {
                peanut.UserGroup
            },
                                                         UserGroupMembership.ActiveTypes).ToList();
            BillCreateViewModel billCreateViewModel = new BillCreateViewModel(new List <UserGroupMembership> {
                currentUsersMembershipsInPeanutGroup
            },
                                                                              availableUserGroupMemberships,
                                                                              peanut);

            billCreateViewModel.BillCreateCommand.UserGroup       = peanut.UserGroup;
            billCreateViewModel.BillCreateCommand.BillDto.Subject = peanut.Name;
            IEnumerable <PeanutParticipation> participations =
                peanut.Participations.Where(s => s.ParticipationState == PeanutParticipationState.Confirmed);

            IDictionary <string, BillUserGroupDebitorDto> userGroupDebitors = new Dictionary <string, BillUserGroupDebitorDto>();

            foreach (PeanutParticipation peanutParticipation in participations)
            {
                UserGroupMembership membership = peanutParticipation.UserGroupMembership;
                userGroupDebitors.Add(membership.BusinessId.ToString(), new BillUserGroupDebitorDto(membership, 1));
            }

            billCreateViewModel.BillCreateCommand.UserGroupDebitors = userGroupDebitors;

            return(View("Create", billCreateViewModel));
        }
예제 #2
0
        public IActionResult Create(BillCreateViewModel vm)
        {
            Bill bill = new Bill(vm.Client, vm.Info)
            {
                Items = vm.Items
            };

            _billRepository.Add(bill);
            _billRepository.SaveChanges();

            return(RedirectToAction(nameof(Index)));
        }
예제 #3
0
        public RestfulResult Create(FormCollection formCollection, BillCreateViewModel vo)
        {
            var tagList = _tagRepository.Get(v => v.Status.Equals((int)DataStatus.Normal) && v.CreatedUser == CurrentUser.CustomerId).ToList();

            if (!this.ModelState.IsValid)
            {
                // 如果我们进行到这一步时某个地方出错,则重新显示表单
                //var dto = new CreateDto { Tags = tagList };
                //dto.Vo = vo;
                //dto.IsError = true;
                //return View("Success",new SuccessViewModel{});
                List<string> sb = new List<string>();
                //获取所有错误的Key
                List<string> Keys = ModelState.Keys.ToList();
                //获取每一个key对应的ModelStateDictionary
                foreach (var key in Keys)
                {
                    var errors = ModelState[key].Errors.ToList();
                    //将错误描述添加到sb中
                    foreach (var error in errors)
                    {
                        sb.Add(error.ErrorMessage);
                    }
                }

                return new RestfulResult
                    {
                        Data = new ExecuteResult<List<string>>(sb) { StatusCode = StatusCode.ClientError, Message = "验证失败" }
                    };
            }

            var newEntity = _mapperManager.BillMapper(vo);
            newEntity.CreatedDate = DateTime.Now;
            newEntity.CreatedUser = base.CurrentUser.CustomerId;
            newEntity.UpdatedDate = DateTime.Now;
            newEntity.UpdatedUser = base.CurrentUser.CustomerId;
            newEntity.Status = (int)DataStatus.Normal;
            newEntity.ExtendedContent = String.Empty;
            newEntity.User_Id = vo.User_Id;
            newEntity.User = _customerRepository.GetItem(base.CurrentUser.CustomerId);

            var entity = this._repository.Insert(newEntity);

            return new RestfulResult
            {
                Data = new ExecuteResult<int>(entity.Id) { StatusCode = StatusCode.Success, Message = "" }
            };
        }