示例#1
0
        public ActionResult Add(MemberAddViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                Member member = Member.Empty();
                member.FirstName   = viewModel.FirstName;
                member.LastName    = viewModel.LastName;
                member.MiddleName  = viewModel.MiddleName;
                member.DateOfBirth = viewModel.DateOfBirth;
                member.GenderId    = viewModel.GenderId;
                member.Email       = viewModel.Email;
                member.Phone       = viewModel.Phone;
                member.Mobile      = viewModel.Mobile;

                if (!string.IsNullOrWhiteSpace(viewModel.Address?.FormattedAddress))
                {
                    member.Address = new Address
                    {
                        CountryId        = Dom.Country.Ukraine,
                        City             = viewModel.Address.City,
                        PostalCode       = viewModel.Address.PostalCode,
                        Street           = viewModel.Address.Street,
                        Number           = viewModel.Address.Number,
                        Latitude         = double.Parse(viewModel.Address.Latitude.Replace(".", ",")),
                        Longitude        = double.Parse(viewModel.Address.Longitude.Replace(".", ",")),
                        FormattedAddress = viewModel.Address.FormattedAddress
                    };
                }

                if (!string.IsNullOrWhiteSpace(viewModel.Website?.Url))
                {
                    member.Website = new Website
                    {
                        Url = viewModel.Website.Url,
                    };
                }

                EntityContext.AddEntityProgress(
                    member.EntityInfo,
                    new EntityProgress
                {
                    OrganizationId     = viewModel.OrganizationId,
                    EntityStateAfterId = Dom.EntityType.Member.State.Created
                }
                    );
                EntityContext.AddEntityOrganization(
                    member.EntityInfo,
                    viewModel.OrganizationId,
                    Dom.EntityType.Member.State.Created
                    );
                _memberRepository.AddOrUpdate(member);
                _memberRepository.UnitOfWork.SaveChanges();

                return(RedirectToAction(Mvc.Controller.Member.List, Mvc.Controller.Member.Name));
            }

            ICollection <SelectListItemCount> organizationItems = _organizationRepository.GetOrganizations(
                UserContext.User.Id,
                UserContext.User.OrganizationId,
                new List <int> {
                Dom.OrganizationType.Club
            }
                );

            viewModel.GenderItems       = InitGenderSelectListItems();
            viewModel.OrganizationItems = Mapper.Map <ICollection <SelectListItem> >(organizationItems);
            return(View(Mvc.View.Member.Add, viewModel));
        }