Ejemplo n.º 1
0
 public HttpResponseMessage Create([FromBody] UserViewModel model)
 {
     try
     {
         if (string.IsNullOrEmpty(model.NickName))
         {
             return(Request.CreateResponse(HttpStatusCode.BadRequest, "Invalid nickName."));
         }
         if (userBusiness.GetByNickName(model.NickName) != null)
         {
             return(Request.CreateResponse(HttpStatusCode.BadRequest, $"User with nickName {model.NickName} already exists."));
         }
         if (string.IsNullOrEmpty(model.ProfileCode))
         {
             return(Request.CreateResponse(HttpStatusCode.BadRequest, $"Invalid profile code."));
         }
         if (profileBusiness.GetByCode(model.ProfileCode) == null)
         {
             return(Request.CreateResponse(HttpStatusCode.NotFound, $"Profile code {model.ProfileCode} does not exist."));
         }
         var userEntity = mapper.MapFromModelToEntity(model);
         userBusiness.Create(userEntity);
         var userModel = userBusiness.GetByNickName(model.NickName);
         return(Request.CreateResponse(HttpStatusCode.Created, userModel));
     }
     catch (Exception ex)
     {
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
     }
 }
Ejemplo n.º 2
0
        public HttpResponseMessage GetByCode(string code)
        {
            try
            {
                if (string.IsNullOrEmpty(code))
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "Invalid code"));
                }
                var profileEntity = profileBusiness.GetByCode(code);
                if (profileEntity == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound, $"Profile with code {code} does not exist."));
                }
                var ProfileViewModel = mapper.MapFromEntityToModel(profileEntity);

                return(Request.CreateResponse(HttpStatusCode.OK, ProfileViewModel));
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }