public HttpResponseMessage Guardar(Categoria entidad) { var resultado = (HttpResponseMessage)null; try { if (entidad == null) { return(Request.CreateResponse(HttpStatusCode.BadRequest, new { message = "El modelo no puede ser nulo" })); } if (string.IsNullOrWhiteSpace(entidad.Descripcion)) { return(Request.CreateResponse(HttpStatusCode.BadRequest, new { message = "La descripción no puede ser nulo o vacío" })); } if (entidad.Id > 0) { _categoriaService.Update(entidad); } else { _categoriaService.Create(entidad); } resultado = Request.CreateResponse(HttpStatusCode.OK, entidad.Id); } catch (Exception exception) { resultado = Request.CreateResponse(HttpStatusCode.InternalServerError, new { message = exception.Message }); } return(resultado); }
private void CreateCategoria() { if (txtNombreCategoria.Text == "") { MessageBox.Show(this, "Complete los campos requeridos", "Error al eliminar", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } c = null; if (cservice.ReadByNombreCategoria(txtNombreCategoria.Text) == null) { c = new Categoria(); c.NombreCategoria = txtNombreCategoria.Text; cservice.Create(c); MessageBox.Show("Categoría registrada"); ClearFields(); FillDataGridViewCategoria(); return; } else { MessageBox.Show(this, "La categoría que intenta registrar ya existe", "Error al registrar", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } }
public CategoriaViewModel Adicionar(CategoriaViewModel categoriaViewModel) { var categoria = _mapper.Map <Categoria>(categoriaViewModel); var retorno = _categoriaService.Create(categoria); categoriaViewModel = _mapper.Map <CategoriaViewModel>(retorno); return(categoriaViewModel); }
public IActionResult Create([FromBody] CategoriaInsertDto item) { try { var id = _service.Create(item); return(CreatedAtAction(nameof(Find), new { id }, item)); } catch (Exception ex) { return(StatusCode(500, ex)); } }
public ActionResult Create(CategoriaInsertDto dto) { try { _service.Create(dto); return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public async Task <ActionResult <Categorias> > PostCiudad(Categorias item) { //Si el mensaje no se recibe con el usuario y token correcto, rechaza la petición if (await ValidateToken() == false) { return(Unauthorized()); } //Adicionar item a la BD _serviceCategoria.Create(item); return(CreatedAtAction(nameof(Categorias), new { id = item.Id }, item)); }
public async Task <ActionResult <Categoria> > PostCategoria(CategoriaDtoRequest categoriaDtoRequest) { var categoria = _mapper.Map <Categoria>(categoriaDtoRequest); var ambiente = await _iAmbienteRepository.FindByIdAsync(categoria.AmbienteId); categoria.Ambiente = ambiente; _categoriaService.Create(categoria); if (_categoriaService.SaveChanges()) { return(Ok(categoria)); } return(BadRequest("Falha no procedimento")); }
public ActionResult Create(CategoriaModel categoria) { if (ModelState.IsValid) { var retorno = _categoriaService.Create(categoria); if (retorno != ERetornoEstabelecimento.SucessoCadastro) { Alert(RetornoHelper.RetornoEstabelecimento(retorno), NotificationType.error); return(View("Create", categoria)); } Alert(RetornoHelper.RetornoEstabelecimento(retorno), NotificationType.success); return(RedirectToAction("Index")); } return(View("Create", categoria)); }
public IActionResult Create(string categoria) { if (!string.IsNullOrEmpty(categoria)) { var persistencia = new Categoria() { Nombre = categoria }; _service.Create(persistencia); TempData["created"] = "Registro Creado Correctamente"; return(RedirectToAction("Index")); } else { TempData["created"] = "Error"; return(RedirectToAction("Index")); } }
public ActionResult Create(JsonHeader collection) { Dictionary <string, string> headerDictionary = WebHelper.JsonToDictionary(collection.Row); JsonResultMessage jsonResultMessage = new JsonResultMessage(); CategoriaDTO categoriaDTO = new CategoriaDTO(); try { if (collection.EditAction == EditActionConstant.EDIT) { categoriaDTO.CategoriaId = Convert.ToInt32(headerDictionary["CategoriaId"]); } categoriaDTO.Codigo = headerDictionary["Codigo"].ToString().Trim(); categoriaDTO.Nombre = headerDictionary["Nombre"].ToString().Trim(); categoriaDTO.Estado = EstadoConstante.ACTIVO; if (collection.EditAction == EditActionConstant.NEW) { _categoriaService.Create(categoriaDTO); } else { _categoriaService.Update(categoriaDTO); } jsonResultMessage.message = "Categoria grabado satifactoriamente"; } catch (Exception ex) { jsonResultMessage.success = false; jsonResultMessage.message = ex.Message; throw ex; } return(Json(jsonResultMessage)); }