public async Task <IActionResult> UpdateCategory([FromBody] UpdateCategoryViewModel category_model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (category_model._id_category < 1) { return(BadRequest()); } var category = await _context.Categories.FirstOrDefaultAsync(c => c._id_category == category_model._id_category); if (category == null) { return(NotFound()); } category.name = category_model.name; category.description = category_model.description; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { return(BadRequest()); } return(Ok()); }
public async Task <IActionResult> RegisterNewUser([FromBody] RegisterUserViewModel user_model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var email = user_model.email.ToLower(); if (await _context.Users.AnyAsync(e => e.email == email)) { return(BadRequest("El email ya está registrado")); } Utils.Utils.EncryptPassword(user_model.password, out byte[] password_hash, out byte[] password_salt); User user = new User { _id_rol = user_model._id_rol, name = user_model.name, kind_of_document = user_model.kind_of_document, document_number = user_model.document_number, adress = user_model.adress, telephone = user_model.telephone, email = user_model.email.ToLower(), password_hash = password_hash, password_salt = password_salt, condition = true }; _context.Users.Add(user); try { await _context.SaveChangesAsync(); } catch (Exception e) { return(BadRequest(e)); } return(Ok()); }
public async Task <IActionResult> UpdateArticle([FromBody] UpdateArticleViewModel article_model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (article_model._id_article < 1) { return(BadRequest()); } if (article_model._id_category < 1) { return(BadRequest()); } var article = await _context.Articles.FirstOrDefaultAsync(k => k._id_article == article_model._id_article); if (article == null) { return(NotFound()); } article._id_category = article_model._id_category; article.code = article_model.code; article.name = article_model.name; article.price = article_model.price; article.stock = article_model.stock; article.description = article_model.description; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { return(BadRequest()); } return(Ok()); }
public async Task <IActionResult> RegisterPerson([FromBody] RegisterPersonViewModel person_model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var email = person_model.email.ToLower(); if (await _context.People.AnyAsync(e => e.email == email)) { return(BadRequest("El email ya está registrado")); } Person person = new Person { kind_of_person = person_model.kind_of_person, name = person_model.name, kind_of_document = person_model.kind_of_document, document_number = person_model.document_number, adress = person_model.adress, telephone = person_model.telephone, email = person_model.email }; _context.People.Add(person); try { await _context.SaveChangesAsync(); } catch (Exception e) { return(BadRequest(e)); } return(Ok()); }