Ejemplo n.º 1
0
 public HttpResponseMessage Creatte(HttpRequestMessage request, FooterViewModel footerVm)
 {
     return(CreateHttpResponse(request, () =>
     {
         if (ModelState.IsValid)
         {
             if (_footerService.GetAll() == null)
             {
                 Footer footerDb = new Footer();
                 footerDb.UpdateFooter(footerVm);
                 _footerService.Add(footerDb);
                 _footerService.SaveChange();
                 return request.CreateResponse(HttpStatusCode.Created, footerVm);
             }
             else
             {
                 return request.CreateErrorResponse(HttpStatusCode.BadRequest, "Đã tồn tại");
             }
         }
         else
         {
             return request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
         }
     }));
 }
Ejemplo n.º 2
0
        public HttpResponseMessage Create(HttpRequestMessage request, FooterViewModel footerViewModel)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                if (!ModelState.IsValid)
                {
                    //trả về lỗi để bên ngoài bắt được sự kiện lỗi này
                    response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    var newpages = new Footer();
                    newpages.UpdateFooter(footerViewModel);

                    _footerService.Add(newpages);
                    _footerService.Save();

                    var responseData = Mapper.Map <Footer, FooterViewModel>(newpages);
                    response = request.CreateResponse(HttpStatusCode.Created, responseData);
                }

                return response;
            }));
        }
Ejemplo n.º 3
0
 public HttpResponseMessage Post(HttpRequestMessage request, FooterViewModel footerVm)
 {
     return(CreateHttpResponse(request, () =>
     {
         HttpResponseMessage response = null;
         if (!ModelState.IsValid)
         {
             request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
         }
         else
         {
             Footer newFooter = new Footer();
             newFooter.UpdateFooter(footerVm);
             var category = _footerService.Add(newFooter);
             _footerService.SaveChanges();
             response = request.CreateResponse(HttpStatusCode.Created, category);
         }
         return response;
     }));
 }
Ejemplo n.º 4
0
 public async Task <HttpResponseMessage> Post(HttpRequestMessage request, FooterViewModel footerVm)
 {
     return(await CreateHttpResponse(request, () =>
     {
         HttpResponseMessage response = null;
         if (ModelState.IsValid)
         {
             request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
         }
         else
         {
             //Khoi tao
             Footer newFooter = new Footer();
             newFooter.UpdateFooter(footerVm); //Gan ViewModel sang Model de Insert DB, this
             //Goi Insert
             var footer = _footerService.Add(newFooter);
             _footerService.SaveAsync();
             response = request.CreateResponse(HttpStatusCode.Created, footer);
         }
         return response;
     }));
 }
Ejemplo n.º 5
0
        public HttpResponseMessage Create(HttpRequestMessage request, FooterViewModel footerVm)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                if (!ModelState.IsValid)
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    var newFooter = new Footer();
                    newFooter.UpdateFooter(footerVm);
                    _footerService.Add(newFooter);
                    _footerService.Save();

                    var responseData = Mapper.Map <Footer, FooterViewModel>(newFooter);
                    response = request.CreateResponse(HttpStatusCode.Created, responseData);
                }

                return response;
            }));
        }
Ejemplo n.º 6
0
 public void Add(Footer footer)
 {
     _footerRepository.Add(footer);
 }