Exemplo n.º 1
0
 public ActionResult Post([FromBody] AddNewsRequestModel model)
 {
     try
     {
         var news = new News()
         {
             CreatedAt     = today,
             Status        = model.Status,
             UpdatedAt     = today,
             Title         = model.Title,
             Date          = model.Date,
             CondominiumId = model.CondominiumId,
             Description   = model.Description,
         };
         _newService.Add(news);
         response.StatusCode = StatusCodes.Status200OK;
         response.Status     = "OK";
         response.Message    = "Condominio agregado";
         return(Ok(response));
     }
     catch (Exception e)
     {
         response.StatusCode = StatusCodes.Status400BadRequest;
         response.Status     = "BAD REQUEST";
         response.Message    = e.Message;
         return(BadRequest(response));
     }
 }
        public HttpResponseMessage Create(HttpRequestMessage request, NewViewModel newVM)
        {
            return(CreateHttpRespond(request, () =>
            {
                HttpResponseMessage response = null;
                if (!ModelState.IsValid)
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
                }
                var news = new New();
                news.UpdateNew(newVM);
                news.CreatedDate = DateTime.Now;
                _newService.Add(news);
                _newService.Save();

                var responseData = Mapper.Map <New, NewViewModel>(news);
                response = request.CreateResponse(HttpStatusCode.Created, responseData);
                return response;
            }));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Add(NewViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var news = new New {
            };

            news.Id      = model.Id;
            news.Name    = model.Name;
            news.Context = model.Context;
            news.Created = DateTime.Now;

            if (model.UploadedPhoto != null)
            {
                news.Photo = await _photoService.AddNew(model.UploadedPhoto, news.Id, _webHostEnvironment.WebRootPath);
            }
            await _newService.Add(news);

            return(RedirectToAction("News"));
        }