public HttpResponseMessage Create(HttpRequestMessage request, NganhNgheViewModel nganhNgheVm)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var newNganhNghe = new NganhNghe();
                    newNganhNghe.UpdateNganhNghe(nganhNgheVm);
                    newNganhNghe.CreatedDate = DateTime.Now;
                    newNganhNghe.CreatedBy   = User.Identity.Name;
                    newNganhNghe.UpdatedDate = DateTime.Now;
                    newNganhNghe.UpdatedBy   = User.Identity.Name;
                    _nganhNgheService.Add(newNganhNghe);
                    _nganhNgheService.Save();

                    var responseData = Mapper.Map <NganhNghe, NganhNgheViewModel>(newNganhNghe);
                    return(request.CreateResponse(HttpStatusCode.Created, responseData));
                }
                catch (NameDuplicatedException dex)
                {
                    return(request.CreateErrorResponse(HttpStatusCode.BadRequest, dex.Message));
                }
            }
            return(request.CreateResponse(HttpStatusCode.BadRequest, ModelState));
        }
Exemple #2
0
 public static void UpdateNganhNghe(this NganhNghe nganhNghe, NganhNgheViewModel nganhNgheVm)
 {
     nganhNghe.Id              = nganhNgheVm.Id;
     nganhNghe.Ten             = nganhNgheVm.Ten;
     nganhNghe.Alias           = nganhNgheVm.Alias;
     nganhNghe.ParentId        = nganhNgheVm.ParentId;
     nganhNghe.CreatedDate     = nganhNgheVm.CreatedDate;
     nganhNghe.CreatedBy       = nganhNgheVm.CreatedBy;
     nganhNghe.UpdatedDate     = nganhNgheVm.UpdatedDate;
     nganhNghe.UpdatedBy       = nganhNgheVm.UpdatedBy;
     nganhNghe.MetaKeyword     = nganhNgheVm.MetaKeyword;
     nganhNghe.MetaDescription = nganhNgheVm.MetaDescription;
     nganhNghe.Status          = nganhNgheVm.Status;
 }