Beispiel #1
0
        public IActionResult Update(MenteeUpdateModel menteeUpdateModel)
        {
            BaseResponseDto responseDto = null;

            if (menteeUpdateModel == null)
            {
                return(BadRequest("Mentee info must not be null"));
            }

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

            return(Ok(responseDto.Message));
        }
        public BaseResponseDto Update(MenteeUpdateModel menteeUpdateModel)
        {
            BaseResponseDto responseDto = null;

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

            Mentee existingMentee = null;

            try
            {
                existingMentee = _uow.GetRepository <Mentee>()
                                 .GetAll()
                                 .Include(m => m.User)
                                 .FirstOrDefault(m => m.MenteeId == menteeUpdateModel.MenteeId);
            }
            catch (Exception e)
            {
                throw e;
            }

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

            existingMentee.User.Email       = menteeUpdateModel.User.Email;
            existingMentee.User.Phone       = menteeUpdateModel.User.Phone;
            existingMentee.User.Fullname    = menteeUpdateModel.User.Fullname;
            existingMentee.User.YearOfBirth = menteeUpdateModel.User.YearOfBirth;
            existingMentee.User.AvatarUrl   = menteeUpdateModel.User.AvatarUrl;
            existingMentee.User.Balance     = menteeUpdateModel.User.Balance;
            existingMentee.User.Description = menteeUpdateModel.User.Description;

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

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

            return(responseDto);
        }