Пример #1
0
        public ServiceMessage Edit(ModeratorEditDTO moderatorDTO)
        {
            List <string> errors    = new List <string>();
            bool          succeeded = Validate(moderatorDTO, errors);

            try
            {
                ModeratorEntity moderatorEntity = unitOfWork.Moderators.GetByLogin(moderatorDTO.Login);
                if (moderatorEntity != null)
                {
                    ApplicationUser applicationUser = moderatorEntity.User;
                    applicationUser.FirstName = moderatorDTO.FirstName;
                    applicationUser.LastName  = moderatorDTO.LastName;

                    unitOfWork.Commit();
                }
                else
                {
                    succeeded = false;
                    errors.Add("Moderator with such login was not found");
                }
            }
            catch (Exception ex)
            {
                ExceptionMessageBuilder.FillErrors(ex, errors);
                succeeded = false;
            }

            return(new ServiceMessage
            {
                Succeeded = succeeded,
                Errors = errors
            });
        }
Пример #2
0
        public ActionResult Edit(ModeratorEditViewModel model)
        {
            bool succeeded = false;

            if (ModelState.IsValid)
            {
                ModeratorEditDTO moderatorDTO   = Mapper.Map <ModeratorEditViewModel, ModeratorEditDTO>(model);
                ServiceMessage   serviceMessage = service.Edit(moderatorDTO);
                if (!serviceMessage.Succeeded)
                {
                    AddModelErrors(serviceMessage.Errors);
                }

                succeeded = serviceMessage.Succeeded;
            }

            return(JsonOnFormPost(succeeded, "~/Views/Moderator/Edit.cshtml", model));
        }
Пример #3
0
        public DataServiceMessage <ModeratorEditDTO> Get(string login)
        {
            List <string>    errors    = new List <string>();
            bool             succeeded = true;
            ModeratorEditDTO data      = null;

            try
            {
                ModeratorEntity moderatorEntity = unitOfWork.Moderators.GetByLogin(login);
                if (moderatorEntity != null)
                {
                    data = new ModeratorEditDTO
                    {
                        Email     = moderatorEntity.User.Email,
                        FirstName = moderatorEntity.User.FirstName,
                        LastName  = moderatorEntity.User.LastName,
                        Login     = login,
                        PhotoLink = moderatorEntity.PhotoLink
                    };
                }
                else
                {
                    succeeded = false;
                    errors.Add("Moderator with such login was not found");
                }
            }
            catch (Exception ex)
            {
                ExceptionMessageBuilder.FillErrors(ex, errors);
                succeeded = false;
            }

            return(new DataServiceMessage <ModeratorEditDTO>
            {
                Succeeded = succeeded,
                Errors = errors,
                Data = data
            });
        }
Пример #4
0
        private bool Validate(ModeratorEditDTO moderatorDTO, ICollection <string> errors)
        {
            bool isValid = true;

            if (String.IsNullOrEmpty(moderatorDTO.FirstName))
            {
                isValid = false;
                errors.Add("First name cannot be empty");
            }

            if (String.IsNullOrEmpty(moderatorDTO.LastName))
            {
                isValid = false;
                errors.Add("Last name cannot be empty");
            }

            if (String.IsNullOrEmpty(moderatorDTO.Email))
            {
                isValid = false;
                errors.Add("Email is required");
            }

            if (String.IsNullOrEmpty(moderatorDTO.Login))
            {
                isValid = false;
                errors.Add("Login is required");
            }

            if (String.IsNullOrEmpty(moderatorDTO.PhotoLink))
            {
                isValid = false;
                errors.Add("Photo is required");
            }

            return(isValid);
        }