예제 #1
0
        public void UpdateRegistrant(RegistrantServiceModel registrant)
        {
            _unitOfWork.AddRepository <RegistrantEntityModel>();

            var registrantEntity = _mapper.Map <RegistrantEntityModel>(registrant);

            _dateService.SetDateEditedNow(ref registrantEntity);

            _unitOfWork.GetRepository <RegistrantEntityModel>().Update(registrantEntity);
            _unitOfWork.Save();
        }
예제 #2
0
        public int CreateRegistrant(RegistrantServiceModel registrant)
        {
            _unitOfWork.AddRepository <RegistrantEntityModel>();

            var registrantEntity = _mapper.Map <RegistrantEntityModel>(registrant);

            _dateService.SetDateCreatedNow(ref registrantEntity);

            _unitOfWork.GetRepository <RegistrantEntityModel>().AddItem(registrantEntity);
            _unitOfWork.Save();

            return(registrantEntity.Id);
        }
예제 #3
0
        public IActionResult OnPost()
        {
            if (ModelState.IsValid)
            {
                int userId = int.Parse(_userService.GetUserId(User));

                var registrant = _registrantService.GetRegistrantByUserId(userId);

                if (registrant == null)
                {
                    registrant = new RegistrantServiceModel
                    {
                        FirstName = Input.FirstName,
                        LastName  = Input.LastName,
                        Address   = Input.Adress,
                        Country   = Input.CountryId,

                        CreatedById = userId,
                        UserId      = userId
                    };

                    _registrantService.CreateRegistrant(registrant);
                }
                else
                {
                    registrant.FirstName = Input.FirstName;
                    registrant.LastName  = Input.LastName;
                    registrant.Address   = Input.Adress;

                    registrant.CountryRelation = null; // setting relation to null so EF doesn't revert changes
                    registrant.Country         = Input.CountryId;

                    registrant.EditedById = userId;

                    _registrantService.UpdateRegistrant(registrant);
                }

                StatusMessage = "Info successfuly updated";
            }

            var countryServiceModels = _nomenclatureService.GetCountries();

            Countries = _mapper.Map <List <CountryModel> >(countryServiceModels);

            return(Page());
        }