//List markom selesai public static ResultResponse Update(SouvenirViewModel entity) { ResultResponse result = new ResultResponse(); try { using (var db = new MarComContext()) { if (entity.Id == 0) { M_Souvenir souvenir = new M_Souvenir(); //souvenir.Code = entity.Code; souvenir.Code = entity.Code; souvenir.Name = entity.Name; souvenir.Description = entity.Description; souvenir.Quantity = entity.Quantity; souvenir.M_Unit_Id = entity.M_Unit_Id; souvenir.Is_Delete = entity.Is_Delete; souvenir.Create_By = "Admin"; souvenir.Create_Date = DateTime.Now; db.M_Souvenir.Add(souvenir); db.SaveChanges(); } else { M_Souvenir souvenir = db.M_Souvenir.Where(s => s.Id == entity.Id).FirstOrDefault(); if (souvenir != null) { souvenir.Code = entity.Code; souvenir.Name = entity.Name; souvenir.Description = entity.Description; souvenir.Quantity = entity.Quantity; souvenir.M_Unit_Id = entity.M_Unit_Id; souvenir.Is_Delete = entity.Is_Delete; souvenir.Update_By = "Admin"; souvenir.Update_Date = DateTime.Now; db.SaveChanges(); } } } } catch (Exception ex) { result.Success = false; result.Message = ex.Message; } return(result); }
public static bool Delete(int id) { bool result = true; try { using (var db = new MarComContext()) { M_Souvenir souvenir = db.M_Souvenir.Where(s => s.Id == id).FirstOrDefault(); if (souvenir != null) { souvenir.Is_Delete = true; db.SaveChanges(); } } } catch (Exception) { return(false); } return(result); }
public static ResultResponse Delete(int id) { ResultResponse result = new ResultResponse(); try { using (var db = new MarComContext()) { M_Souvenir souvenir = db.M_Souvenir.Where(s => s.Id == id).FirstOrDefault(); if (souvenir != null) { souvenir.Is_Delete = true; db.SaveChanges(); result.Message = "Data Deleted ! Data souvenir with code " + souvenir.Code + " has been deleted"; } } } catch (Exception) { result.Success = false; result.Message = "Delete Data not success"; } return(result); }
//List markom selesai public static ResultResponse Update(SouvenirViewModel entity) { ResultResponse result = new ResultResponse(); try { using (var db = new MarComContext()) { if (entity.Id == 0) { bool notExist = db.M_Souvenir.Any(ms => ms.Name.Equals(entity.Name)); if (notExist) { result.Success = false; result.Message = "Souvenir with name " + entity.Name + " already Exist !"; } else { M_Souvenir souvenir = new M_Souvenir(); souvenir.Code = entity.Code; souvenir.Name = entity.Name; souvenir.Description = entity.Description; souvenir.Quantity = entity.Quantity; souvenir.M_Unit_Id = entity.M_Unit_Id; souvenir.Is_Delete = entity.Is_Delete; souvenir.Create_By = entity.Create_By; souvenir.Create_Date = DateTime.Now; db.M_Souvenir.Add(souvenir); db.SaveChanges(); result.Message = "Data Saved ! New Souvenier has been add with code " + entity.Code; } } else { M_Souvenir souvenir = db.M_Souvenir.Where(s => s.Id == entity.Id).FirstOrDefault(); if (souvenir != null) { bool notExist = db.M_Souvenir.Any(ms => ms.Name.Equals(entity.Name) && ms.Code != entity.Code); if (notExist) { result.Success = false; result.Message = "Souvenir with name " + entity.Name + " already Exist !"; } else { souvenir.Name = entity.Name; souvenir.Description = entity.Description; souvenir.Quantity = entity.Quantity; souvenir.M_Unit_Id = entity.M_Unit_Id; //souvenir.Is_Delete = entity.Is_Delete; souvenir.Update_By = entity.Update_By; souvenir.Update_Date = DateTime.Now; db.SaveChanges(); result.Message = "Data Update ! Data Souvenir has been updated"; } } } } } catch (Exception ex) { result.Success = false; result.Message = ex.Message; } return(result); }