Exemplo n.º 1
0
        public IActionResult Update(MentorUpdateModel mentorModel)
        {
            BaseResponseDto responseDto = null;

            if (mentorModel == null)
            {
                return(BadRequest("Mentor info must not be null"));
            }

            try
            {
                responseDto = _mentor.Update(mentorModel);
            }
            catch (Exception e)
            {
                return(StatusCode(500, e.Message + "  \n  \n  \n  " + e.StackTrace));
            }

            return(Ok(responseDto.Message));
        }
Exemplo n.º 2
0
        public BaseResponseDto Update(MentorUpdateModel mentorUpdateModel)
        {
            BaseResponseDto responseDto = null;

            if (mentorUpdateModel == null)
            {
                responseDto = new BaseResponseDto
                {
                    Status  = 1,
                    Message = "Faulthy mentor info"
                };
                return(responseDto);
            }

            Mentor existingMentor = null;

            try
            {
                existingMentor = _uow.GetRepository <Mentor>()
                                 .GetAll()
                                 .Include(m => m.User)
                                 .FirstOrDefault(m => m.MentorId == mentorUpdateModel.MentorId);
            }
            catch (Exception e)
            {
                throw e;
            }

            if (existingMentor == null)
            {
                responseDto = new BaseResponseDto
                {
                    Status  = 2,
                    Message = "No existing mentor with specified id found"
                };
                return(responseDto);
            }

            existingMentor.User.Email       = mentorUpdateModel.User.Email;
            existingMentor.User.Phone       = mentorUpdateModel.User.Phone;
            existingMentor.User.Fullname    = mentorUpdateModel.User.Fullname;
            existingMentor.User.YearOfBirth = mentorUpdateModel.User.YearOfBirth;
            existingMentor.User.AvatarUrl   = mentorUpdateModel.User.AvatarUrl;
            existingMentor.User.Balance     = mentorUpdateModel.User.Balance;
            existingMentor.User.Description = mentorUpdateModel.User.Description;

            try
            {
                _uow.GetRepository <Mentor>().Update(existingMentor);
                _uow.Commit();
            }
            catch (Exception e)
            {
                throw e;
            }

            responseDto = new BaseResponseDto
            {
                Status  = 0,
                Message = "Success"
            };

            return(responseDto);
        }