Beispiel #1
0
        public HttpResponseMessage Put(HttpRequestMessage request, DaoTaoLienTucViewModel daoTaoLienTucVm)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                if (ModelState.IsValid)
                {
                    DaoTaoLienTuc dbDaoTaoLienTuc = _daoTaoLienTucService.GetById(daoTaoLienTucVm.ID);
                    dbDaoTaoLienTuc.UpdateDaoTaoLienTuc(daoTaoLienTucVm);
                    dbDaoTaoLienTuc.NgayCapNhat = DateTime.Now;
                    dbDaoTaoLienTuc.NguoiCapNhat = User.Identity.Name;
                    _daoTaoLienTucService.Update(dbDaoTaoLienTuc);
                    _daoTaoLienTucService.SaveChanges();

                    var responseData = Mapper.Map <DaoTaoLienTucViewModel>(dbDaoTaoLienTuc);
                    response = request.CreateResponse(HttpStatusCode.Created, responseData);
                }
                else
                {
                    request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
                }
                return response;
            }));
        }
Beispiel #2
0
        public HttpResponseMessage Post(HttpRequestMessage request, DaoTaoLienTucViewModel daoTaoLienTucVm)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                if (ModelState.IsValid)
                {
                    DaoTaoLienTuc newDaoTaoLienTuc = new DaoTaoLienTuc();
                    newDaoTaoLienTuc.UpdateDaoTaoLienTuc(daoTaoLienTucVm);
                    newDaoTaoLienTuc.NgayTao = DateTime.Now;
                    newDaoTaoLienTuc.NguoiTao = User.Identity.Name;
                    var daoTaoLienTuc = _daoTaoLienTucService.Add(newDaoTaoLienTuc);
                    _daoTaoLienTucService.SaveChanges();

                    var responseData = Mapper.Map <DaoTaoLienTucViewModel>(daoTaoLienTuc);
                    response = request.CreateResponse(HttpStatusCode.Created, responseData);
                }
                else
                {
                    request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
                }
                return response;
            }));
        }