public void saveCategory(frmCategoryDetail frmCategory) { try { if (validateCategory(frmCategory)) { TblCategoryDTO categoryDTO = new TblCategoryDTO(); categoryDTO.name = frmCategory.getCategoryName().Text; categoryDTO.idCategory = form.getIdCategory().Text; if (!frmCategory.getStateUpdate()) { categoryModel.addCategory(categoryDTO); MessageBox.Show(MessageUtil.SAVE_SUCCESS); getAllCategory(); getAllProduct(); } else { categoryModel.updateCategory(categoryDTO); MessageBox.Show(MessageUtil.SAVE_SUCCESS); getAllCategory(); getAllProduct(); } } }catch (Exception e) { MessageBox.Show(MessageUtil.ERROR + " Save Category"); } }
public bool update(TblCategoryDTO categoryDTO) { string sql = "Update tblCategory set name=@name where idCategory=@idCategory"; try { cn = DBUtil.MakeConnect(); if (cn != null) { cmd = new SqlCommand(sql, cn); cmd.Parameters.AddWithValue("@name", categoryDTO.name); cmd.Parameters.AddWithValue("@idCategory", categoryDTO.idCategory); return(cmd.ExecuteNonQuery() > 0); } return(false); }catch (Exception e) { Console.WriteLine(e.Message); throw new Exception(e.Message); } finally { DBUtil.CloseConnection(null, cn); } }
public bool add(TblCategoryDTO categoryDTO) { string sql = "Insert into tblCategory(idCategory,name) values (@idCategory,@name) "; try { cn = DBUtil.MakeConnect(); if (cn != null) { cmd = new SqlCommand(sql, cn); cmd.Parameters.AddWithValue("@idCategory", Guid.NewGuid().ToString()); cmd.Parameters.AddWithValue("@name", categoryDTO.name); return(cmd.ExecuteNonQuery() > 0); } return(false); }catch (Exception e) { Console.WriteLine(e.Message); throw new Exception(e.Message); } finally { DBUtil.CloseConnection(null, cn); } }
public bool addCategory(TblCategoryDTO categoryDTO) { try { HttpResponseMessage responseMessage = ApiConnection.loadPostJsonObject("category/addCategory", categoryDTO, Program.TokenGlobal); if (responseMessage.IsSuccessStatusCode) { return(true); } return(false); } catch (Exception e) { throw e; } }
public IActionResult updateCategory([FromBody] TblCategoryDTO categoryDTO) { bool isValidToken = ValidateToken(); if (isValidToken) { TblCategoryDAO dao = new TblCategoryDAO(); try { if (dao.update(categoryDTO)) { return(Ok(categoryDTO)); } } catch (Exception e) { return(StatusCode(500)); } } return(Unauthorized()); }
public List <TblCategoryDTO> loadCategory() { string sql = "SELECT idCategory, name FROM tblCategory"; try { cn = DBUtil.MakeConnect(); if (cn != null) { cmd = new SqlCommand(sql, cn); reader = cmd.ExecuteReader(); List <TblCategoryDTO> listCategory = null; while (reader.Read()) { TblCategoryDTO dto = new TblCategoryDTO(); dto.idCategory = reader["idCategory"].ToString(); dto.name = reader["name"].ToString(); if (listCategory == null) { listCategory = new List <TblCategoryDTO>(); } listCategory.Add(dto); } return(listCategory); } } catch (SqlException e) { throw new Exception(e.Message); } finally { DBUtil.CloseConnection(reader, cn); } return(null); }