public void DeleteRecipeProduct(RecipeProductModels model, int ProductType) { using (var cxt = new NuWebContext()) { if (ProductType == (byte)Commons.EProductType.Dish) { var item = cxt.I_Recipe_Item.Where(s => s.Id == model.Id).FirstOrDefault(); if (item != null) { item.Status = (byte)Commons.EStatus.Deleted; item.UpdatedBy = model.UpdatedBy; item.UpdatedDate = DateTime.Now; cxt.SaveChanges(); } } else if (ProductType == (byte)Commons.EProductType.Modifier) { var item = cxt.I_Recipe_Modifier.Where(s => s.Id == model.Id).FirstOrDefault(); if (item != null) { item.Status = (byte)Commons.EStatus.Deleted; item.UpdatedBy = model.UpdatedBy; item.UpdatedDate = DateTime.Now; cxt.SaveChanges(); } } } }
public bool DeleteListIdRecipeProduct(string ItemId, string storeId, List <string> listUpdate, int ProductType) { bool result = false; using (var cxt = new NuWebContext()) { try { if (ProductType == (byte)Commons.EProductType.Dish) { var listAllId = (from RI in cxt.I_Recipe_Item where RI.ItemId.Equals(ItemId) && RI.StoreId.Equals(storeId) && RI.Status != (int)Commons.EStatus.Deleted select RI.Id).ToList(); var listIdDelete = listAllId.Where(a => !(listUpdate.Select(x => x).ToList()).Any(a1 => a1 == a)).ToList(); var listDelete = (from RI in cxt.I_Recipe_Item where listIdDelete.Contains(RI.Id) select RI).ToList(); listDelete.ForEach(x => x.Status = (int)Commons.EStatus.Deleted); cxt.SaveChanges(); } else if (ProductType == (byte)Commons.EProductType.Modifier) { var listAllId = (from RM in cxt.I_Recipe_Modifier where RM.ModifierId.Equals(ItemId) && RM.StoreId.Equals(storeId) && RM.Status != (int)Commons.EStatus.Deleted select RM.Id).ToList(); var listIdDelete = listAllId.Where(a => !(listUpdate.Select(x => x).ToList()).Any(a1 => a1 == a)).ToList(); var listDelete = (from RI in cxt.I_Recipe_Modifier where listIdDelete.Contains(RI.Id) select RI).ToList(); listDelete.ForEach(x => x.Status = (int)Commons.EStatus.Deleted); cxt.SaveChanges(); } result = true; } catch (Exception e) { _logger.Error("GetListIdRecipeProduct: " + e); } finally { if (cxt != null) { cxt.Dispose(); } } } return(result); }
public bool Insert(CountryModels model, ref string msg) { bool result = true; using (NuWebContext cxt = new NuWebContext()) { try { I_Country item = new I_Country(); item.Id = Guid.NewGuid().ToString(); item.ShortName = model.ShortName; item.FullName = model.FullName; item.ZipCode = model.ZipCode; item.IsActived = model.IsActived; cxt.I_Country.Add(item); cxt.SaveChanges(); } catch (Exception ex) { _logger.Error(ex); result = false; } finally { if (cxt != null) { cxt.Dispose(); } } } return(result); }
public bool Delete(string RoleId, ref string msg) { bool result = true; using (NuWebContext cxt = new NuWebContext()) { try { var lstResult = (from tb in cxt.G_RoleOnStore where tb.RoleId.Equals(RoleId) select tb).ToList(); cxt.G_RoleOnStore.RemoveRange(lstResult); cxt.SaveChanges(); } catch (Exception ex) { _logger.Error(ex); result = false; } finally { if (cxt != null) { cxt.Dispose(); } } } return(result); }
public bool Delete(string RoleID, ref string msg) { bool result = true; using (NuWebContext cxt = new NuWebContext()) { try { var lstResult = (from mp in cxt.G_ModulePermission where mp.RoleID.Equals(RoleID) select mp).ToList(); cxt.G_ModulePermission.RemoveRange(lstResult); cxt.SaveChanges(); } catch (Exception ex) { _logger.Error(ex); result = false; } finally { if (cxt != null) { cxt.Dispose(); } } } return(result); }
public bool Update(CountryModels model, ref string msg) { bool result = true; using (NuWebContext cxt = new NuWebContext()) { try { var itemUpdate = (from tb in cxt.I_Country where tb.Id == model.Id select tb).FirstOrDefault(); itemUpdate.ShortName = model.ShortName; itemUpdate.FullName = model.FullName; itemUpdate.ZipCode = model.ZipCode; itemUpdate.IsActived = model.IsActived; cxt.SaveChanges(); } catch (Exception ex) { _logger.Error(ex); result = false; } finally { if (cxt != null) { cxt.Dispose(); } } } return(result); }
public bool Delete(string Id, ref string msg) { bool result = true; using (NuWebContext cxt = new NuWebContext()) { try { I_Stock_Transfer_Detail itemDelete = (from tb in cxt.I_Stock_Transfer_Detail where tb.Id == Id select tb).FirstOrDefault(); //cxt.I_Stock_Transfer_Detail.Remove(itemDelete); cxt.SaveChanges(); } catch (Exception ex) { _logger.Error(ex); result = false; } finally { if (cxt != null) { cxt.Dispose(); } } } return(result); }
public bool Delete(List <string> lstId, ref string msg) { bool result = true; using (NuWebContext cxt = new NuWebContext()) { try { List <I_Purchase_Order_Detail> listDelete = (from tb in cxt.I_Purchase_Order_Detail where lstId.Contains(tb.Id) select tb).ToList(); if (listDelete != null && listDelete.Count > 0) { cxt.I_Purchase_Order_Detail.RemoveRange(listDelete); cxt.SaveChanges(); } } catch (Exception ex) { _logger.Error(ex); result = false; } finally { if (cxt != null) { cxt.Dispose(); } } } return(result); }
public ResultModels DeleteUpdateCurrentSchedulerTask(SettingSchedulerTaskModels model) { try { using (var cxt = new NuWebContext()) { using (var dbContextTransaction = cxt.Database.BeginTransaction()) { try { var schedulerTaskOnStore = cxt.G_ScheduleTaskOnStore.FirstOrDefault(x => x.ScheduleTaskId == model.ID); cxt.G_ScheduleTaskOnStore.Remove(schedulerTaskOnStore); var schedulerTask = cxt.G_ScheduleTask.FirstOrDefault(x => x.Id == model.ID && x.ReportId == model.ReportId); cxt.G_ScheduleTask.Remove(schedulerTask); cxt.SaveChanges(); dbContextTransaction.Commit(); StatusResponse.IsOk = true; StatusResponse.Message = "Scheduler Task delete successful."; } catch (Exception) { dbContextTransaction.Rollback(); } } } } catch (Exception) { StatusResponse.IsOk = false; StatusResponse.Message = "Scheduler Task delete fail!!!"; } return(StatusResponse); }
public ResultModels EnableActive(List <string> lstId, bool active) { //if (!active) //{ // lstId = ListIngInActive(lstId); //} ResultModels data = new ResultModels(); using (var cxt = new NuWebContext()) { var lstObj = cxt.I_Supplier.Where(ww => lstId.Contains(ww.Id)).ToList(); if (lstObj != null && lstObj.Count > 0) { lstObj.ForEach(ss => ss.IsActived = active); cxt.SaveChanges(); data.IsOk = true; } else { data.IsOk = false; data.Message = "Not found!"; } } return(data); }
public ResultModels InsertUnit(UnitOfMeasureModel model) { ResultModels result = new ResultModels(); result.IsOk = true; using (var cxt = new NuWebContext()) { //check code var itemDb = cxt.I_UnitOfMeasure.Where(ww => ww.Code.ToUpper() == model.Code.Trim().ToUpper()).FirstOrDefault(); if (itemDb != null) { result.IsOk = false; result.Message = "UOM is exist!"; return(result); } var item = new I_UnitOfMeasure(); item.Id = Guid.NewGuid().ToString(); item.Code = item.Code.Trim(); item.Name = item.Name; item.IsActive = item.IsActive; item.UpdatedBy = item.UpdatedBy; item.UpdatedDate = DateTime.Now; item.CreatedBy = item.CreatedBy; item.CreatedDate = item.CreatedDate; item.Status = (int)Commons.EStatus.Actived; cxt.I_UnitOfMeasure.Add(item); cxt.SaveChanges(); } return(result); }
public bool Insert(List <DiscountAndMiscReportModels> lstInfo) { var result = true; var info = lstInfo.FirstOrDefault(); using (NuWebContext cxt = new NuWebContext()) { //Check Exist var obj = cxt.R_DiscountAndMiscReport.Where(ww => ww.StoreId == info.StoreId && ww.CreatedDate == info.CreatedDate).FirstOrDefault(); if (obj != null) { NSLog.Logger.Info("Insert Misc data exist"); return(result); } using (var transaction = cxt.Database.BeginTransaction()) { try { List <R_DiscountAndMiscReport> lstInsert = new List <R_DiscountAndMiscReport>(); R_DiscountAndMiscReport itemInsert = null; foreach (var item in lstInfo) { itemInsert = new R_DiscountAndMiscReport(); itemInsert.Id = Guid.NewGuid().ToString(); itemInsert.StoreId = item.StoreId; itemInsert.CreatedDate = item.CreatedDate; itemInsert.DiscountValue = item.DiscountValue; itemInsert.MiscValue = item.MiscValue; itemInsert.Mode = item.Mode; lstInsert.Add(itemInsert); } cxt.R_DiscountAndMiscReport.AddRange(lstInsert); cxt.SaveChanges(); transaction.Commit(); NSLog.Logger.Info("Insert Misc data success", lstInfo); } catch (Exception ex) { NSLog.Logger.Error("Insert Misc data fail", ex); //_logger.Error(ex); result = false; transaction.Rollback(); } finally { if (cxt != null) { cxt.Dispose(); } } } } //var jsonContent = JsonConvert.SerializeObject(lstInfo); //_baseFactory.InsertTrackingLog("R_DiscountAndMiscReport", jsonContent, info.StoreId.ToString(), result); return(result); }
public bool Delete(string Id, ref string msg) { bool result = true; using (NuWebContext cxt = new NuWebContext()) { try { I_DataEntry itemDelete = (from tb in cxt.I_DataEntry where tb.Id == Id select tb).FirstOrDefault(); if (itemDelete != null) { itemDelete.IsActived = false; } cxt.SaveChanges(); } catch (Exception ex) { _logger.Error(ex); result = false; } finally { if (cxt != null) { cxt.Dispose(); } } } return(result); }
public bool UpdateTimeSettingForFJDailySale(MerchantConfigApiModels model) { using (var cxt = new NuWebContext()) { try { var result = cxt.G_POSAPIMerchantConfig.Where(ww => ww.Id == model.Id) .FirstOrDefault(); if (result != null) { result.MorningStart = model.MorningStart; result.MorningEnd = model.MorningEnd; result.MidDayStart = model.MidDayStart; result.MidDayEnd = model.MidDayEnd; cxt.SaveChanges(); } NSLog.Logger.Info("UpdateTimeSettingForFJDailySale", result); return(true); } catch (Exception ex) { NSLog.Logger.Error("GetTimeSettingForFJDailySale", ex); return(false); } } }
public bool EnableActive(List <string> lstId, bool active) { //if (!active) //{ // lstId = ListIngInActive(lstId); //} bool result = true; using (NuWebContext cxt = new NuWebContext()) { try { var resuft = cxt.I_UnitOfMeasure.Where(ss => lstId.Contains(ss.Id)).ToList(); foreach (var item in resuft) { item.IsActive = active; } cxt.SaveChanges(); } catch (Exception ex) { _logger.Error(ex); } } return(result); }
public bool Update(ReturnNoteDetailModels model, ref string msg) { bool result = true; using (NuWebContext cxt = new NuWebContext()) { try { //var itemUpdate = (from tb in cxt.I_Return_Note_Detail // where tb.Id == model.Id // select tb).FirstOrDefault(); //itemUpdate.ReceiptNoteId = model.ReceiptNoteDetailId; //itemUpdate.ReceivedQty = model.ReceivedQty; //itemUpdate.ReturnQty = model.ReturnQty; //itemUpdate.IsActived = model.IsActived; cxt.SaveChanges(); } catch (Exception ex) { _logger.Error(ex); result = false; } finally { if (cxt != null) { cxt.Dispose(); } } } return(result); }
public void UpdateRecipeIngredient(RecipeIngredientModels model) { using (var cxt = new NuWebContext()) { using (var transaction = cxt.Database.BeginTransaction()) { try { var item = cxt.I_Recipe_Ingredient.Where(s => s.Id == model.Id).FirstOrDefault(); if (item != null) { item.UOMId = model.UOMId; item.Usage = model.Usage; item.BaseUsage = model.BaseUsage; item.UpdatedBy = model.UpdatedBy; item.UpdatedDate = DateTime.Now; cxt.SaveChanges(); transaction.Commit(); } } catch (Exception e) { _logger.Error("RecipeProduct_Update: " + e); transaction.Rollback(); } finally { if (cxt != null) { cxt.Dispose(); } } } } }
public bool DeleteListIdRecipeIngredient(string MixtureIngredientId, List <string> listUpdate) { bool result = false; using (var cxt = new NuWebContext()) { try { var listAllId = (from RI in cxt.I_Recipe_Ingredient where RI.MixtureIngredientId.Equals(MixtureIngredientId) && RI.Status != (int)Commons.EStatus.Deleted select RI.Id).ToList(); var listIdDelete = listAllId.Where(a => !(listUpdate.Select(x => x).ToList()).Any(a1 => a1 == a)).ToList(); var listDelete = (from RI in cxt.I_Recipe_Ingredient where listIdDelete.Contains(RI.Id) select RI).ToList(); listDelete.ForEach(x => x.Status = (int)Commons.EStatus.Deleted); cxt.SaveChanges(); result = true; } catch (Exception e) { _logger.Error("GetListIdRecipeIngredient: " + e); } finally { if (cxt != null) { cxt.Dispose(); } } } return(result); }
public bool Update(DataEntryDetailModels model, ref string msg) { bool result = true; using (NuWebContext cxt = new NuWebContext()) { try { var itemUpdate = (from tb in cxt.I_DataEntryDetail where tb.Id == model.Id select tb).FirstOrDefault(); itemUpdate.DataEntryId = model.DataEntryId; itemUpdate.IngredientId = model.IngredientId; //itemUpdate.CloseBal = 0; //model.CloseBal; cxt.SaveChanges(); } catch (Exception ex) { _logger.Error(ex); result = false; } finally { if (cxt != null) { cxt.Dispose(); } } } return(result); }
public bool Insert(List <ReceiptNoteDetailModels> models, ref string msg) { using (var cxt = new NuWebContext()) { try { List <I_ReceiptNoteDetail> ListInsert = new List <I_ReceiptNoteDetail>(); I_ReceiptNoteDetail item = null; foreach (var model in models) { item = new I_ReceiptNoteDetail(); item.Id = Guid.NewGuid().ToString(); item.ReceiptNoteId = model.ReceiptNoteId; item.PurchaseOrderDetailId = model.PurchaseOrderDetailId; item.ReceivedQty = model.ReceivedQty; item.ReceivingQty = model.ReceivingQty; item.RemainingQty = model.RemainingQty; ListInsert.Add(item); } cxt.I_ReceiptNoteDetail.AddRange(ListInsert); cxt.SaveChanges(); return(true); } catch (Exception ex) { _logger.Error(ex); return(false); } } }
public bool Update(DataEntryModels model, ref string msg) { bool result = true; ResultModels resultModels = new ResultModels(); using (NuWebContext cxt = new NuWebContext()) { using (var transaction = cxt.Database.BeginTransaction()) { try { var itemUpdate = (from tb in cxt.I_DataEntry where tb.Id == model.Id select tb).FirstOrDefault(); itemUpdate.ModifierBy = model.ModifierBy; itemUpdate.ModifierDate = model.ModifierDate; itemUpdate.IsActived = model.IsActived; //Detail //Check item insert var lstDetailId = model.ListItem.Select(ss => ss.Id).ToList(); if (lstDetailId != null && lstDetailId.Count > 0) { var lstDetailUpdate = cxt.I_DataEntryDetail.Where(ww => lstDetailId.Contains(ww.Id)).ToList(); foreach (var item in model.ListItem) { var obj = lstDetailUpdate.Where(ww => ww.Id == item.Id).FirstOrDefault(); if (obj != null) { obj.Damage = item.Damage; obj.Wastage = item.Wast; obj.OrderQty = item.OrderQty; obj.Reasons = item.Reasons; } } } cxt.SaveChanges(); transaction.Commit(); } catch (Exception ex) { _logger.Error(ex); result = false; transaction.Rollback(); } finally { if (cxt != null) { cxt.Dispose(); } } } } return(result); }
public void UpdateRecipeProduct(RecipeProductModels model, int ProductType) { using (var cxt = new NuWebContext()) { try { if (ProductType == (byte)Commons.EProductType.Dish) { var item = cxt.I_Recipe_Item.Where(s => s.Id == model.Id).FirstOrDefault(); if (item != null) { item.UOMId = model.UOMId; item.Usage = model.Usage; item.BaseUsage = model.BaseUsage; item.UpdatedBy = model.UpdatedBy; item.UpdatedDate = DateTime.Now; cxt.SaveChanges(); } } else if (ProductType == (byte)Commons.EProductType.Modifier) { var item = cxt.I_Recipe_Modifier.Where(s => s.Id == model.Id).FirstOrDefault(); if (item != null) { item.UOMId = model.UOMId; item.Usage = model.Usage; item.BaseUsage = model.BaseUsage; item.UpdatedBy = model.UpdatedBy; item.UpdatedDate = DateTime.Now; cxt.SaveChanges(); } } } catch (Exception e) { _logger.Error("RecipeProduct_Update: " + e); } } }
public bool ChangePassword(EmployeeModels model, ref string msg, string mec) { try { SBEmployeeApiModels paraBody = new SBEmployeeApiModels(); paraBody.AppKey = Commons.AppKey; paraBody.AppSecret = Commons.AppSecret; paraBody.CreatedUser = Commons.CreateUser; paraBody.ID = model.ID; paraBody.OldPassword = CommonHelper.GetSHA512(model.OldPassword); paraBody.NewPassword = CommonHelper.GetSHA512(model.NewPassword); var result = (ResponseApiModels)ApiResponse.Post <ResponseApiModels>(Commons.ChangePassword, null, paraBody); if (result != null) { if (result.Success) { using (NuWebContext cxt = new NuWebContext()) { try { var IsCheckExist = cxt.G_POSEmployeeConfig.Where(x => x.UserName == model.Email).FirstOrDefault(); if (IsCheckExist != null) { IsCheckExist.Password = CommonHelper.GetSHA512(model.NewPassword); cxt.SaveChanges(); } } catch (Exception ex) { _logger.Error("Update EmployeeConfig " + ex); return(false); } } return(true); } else { msg = result.Message; _logger.Error(result.Message); return(false); } } else { _logger.Error(result); return(false); } } catch (Exception ex) { _logger.Error("Employee_ChangePassword: " + ex); //msg = e.ToString(); return(false); } }
public bool Insert(LanguageModels info) { bool result = false; using (NuWebContext cxt = new NuWebContext()) { using (var transaction = cxt.Database.BeginTransaction()) { try { var isExsit = cxt.G_Language.Any(x => x.Symbol.ToLower().Equals(info.Symbol.ToLower())); if (isExsit) { return(result); } G_Language item = new G_Language(); item.Id = Guid.NewGuid().ToString(); item.Name = info.Name; item.Symbol = info.Symbol; item.Status = (byte)Commons.EStatus.Actived; item.IsDefault = info.IsDefault; item.CreatedDate = DateTime.Now; item.LastModified = DateTime.Now; item.CreatedUser = info.CreatedUser; item.ModifiedUser = info.ModifiedUser; cxt.G_Language.Add(item); cxt.SaveChanges(); transaction.Commit(); result = true; NSLog.Logger.Info("Insert [Insert Language] data success", info); } catch (Exception ex) { NSLog.Logger.Error("Insert [Insert Language] data fail", ex); //_logger.Error(ex); result = false; transaction.Rollback(); } finally { if (cxt != null) { cxt.Dispose(); } } } } //var jsonContent = JsonConvert.SerializeObject(info); //_baseFactory.InsertTrackingLog("G_POSAPIMerchantConfig", jsonContent, info.NuPOSInstance, result); return(result); }
public bool Insert(List <TaxModels> lstInfo) { bool result = true; var info = lstInfo.FirstOrDefault(); using (NuWebContext cxt = new NuWebContext()) { using (var transaction = cxt.Database.BeginTransaction()) { try { List <G_Tax> lstInsert = new List <G_Tax>(); G_Tax itemInsert = null; foreach (var item in lstInfo) { itemInsert = new G_Tax(); itemInsert.Id = Guid.NewGuid().ToString(); itemInsert.StoreId = item.StoreId; itemInsert.Name = item.Name; itemInsert.TaxType = item.TaxType; itemInsert.Percent = item.Percent; itemInsert.IsActive = item.IsActive; itemInsert.DateCreated = item.DateCreated; itemInsert.UserCreated = item.UserCreated; lstInsert.Add(itemInsert); } cxt.G_Tax.AddRange(lstInsert); cxt.SaveChanges(); transaction.Commit(); NSLog.Logger.Info("Insert Tax data success", lstInfo); } catch (Exception ex) { NSLog.Logger.Error("Insert Tax data fail", ex); //_logger.Error(ex); result = false; transaction.Rollback(); } finally { if (cxt != null) { cxt.Dispose(); } } } } //var jsonContent = JsonConvert.SerializeObject(lstInfo); //_baseFactory.InsertTrackingLog("G_Tax", jsonContent, info.StoreId.ToString(), result); return(result); }
/*Employee*/ public bool InsertEmployee(EmployeeConfigApiModels info) { bool result = true; using (NuWebContext cxt = new NuWebContext()) { using (var transaction = cxt.Database.BeginTransaction()) { try { G_POSEmployeeConfig itemInsert = null; itemInsert = new G_POSEmployeeConfig(); if (string.IsNullOrEmpty(info.Id)) { itemInsert.Id = Guid.NewGuid().ToString(); } else { itemInsert.Id = info.Id; } itemInsert.POSAPIMerchantConfigId = info.POSAPIMerchantConfigId; itemInsert.UserName = info.UserName; itemInsert.Password = CommonHelper.GetSHA512(info.Password); itemInsert.CreatedDate = DateTime.Now; itemInsert.IsActived = true; cxt.G_POSEmployeeConfig.Add(itemInsert); cxt.SaveChanges(); transaction.Commit(); NSLog.Logger.Info("Insert [Insert Pos Api Employee Config] data success", info); } catch (Exception ex) { NSLog.Logger.Error("Insert [Insert Pos Api Employee Config] data fail", ex); //_logger.Error(ex); result = false; transaction.Rollback(); } finally { if (cxt != null) { cxt.Dispose(); } } } } //var jsonContent = JsonConvert.SerializeObject(info); //_baseFactory.InsertTrackingLog("G_POSEmployeeConfig", jsonContent, info.POSAPIMerchantConfigId, result); return(result); }
public ResultModels UpdateCurrentSchedulerTask(SettingSchedulerTaskModels model) { try { using (var cxt = new NuWebContext()) { using (var dbContextTransaction = cxt.Database.BeginTransaction()) { try { var schedulerTask = cxt.G_ScheduleTask.FirstOrDefault(x => x.Id == model.ID && x.ReportId == model.ReportId); schedulerTask.EmailSubject = model.EmailSubject; schedulerTask.Email = model.Email; schedulerTask.Cc = model.Cc; schedulerTask.Bcc = model.Bcc; schedulerTask.Hour = model.Hour; schedulerTask.Minute = model.Minute; schedulerTask.Enabled = model.Enabled; schedulerTask.IsDaily = model.IsDaily; schedulerTask.IsMonthly = model.IsMonth; schedulerTask.LastDateModified = DateTime.Now; // for scheduler task on store var schedulerTaskOnStore = cxt.G_ScheduleTaskOnStore.FirstOrDefault(x => x.ScheduleTaskId == model.ID /*&& x.StoreId == model.StoreId*/); schedulerTaskOnStore.Id = schedulerTaskOnStore.Id; schedulerTaskOnStore.ScheduleTaskId = schedulerTask.Id; schedulerTaskOnStore.StoreId = model.StoreId; schedulerTaskOnStore.Description = model.Description; schedulerTaskOnStore.LastDateModified = DateTime.Now; cxt.SaveChanges(); dbContextTransaction.Commit(); StatusResponse.IsOk = true; StatusResponse.Message = "Scheduler Task update successful."; } catch (Exception) { dbContextTransaction.Rollback(); } } } } catch (Exception ex) { string error = ex.ToString(); StatusResponse.IsOk = false; StatusResponse.Message = "Scheduler Task update fail!!!"; } return(StatusResponse); }
public void DeleteRecipeIngredient(RecipeIngredientModels model) { using (var cxt = new NuWebContext()) { var item = cxt.I_Recipe_Ingredient.Where(s => s.Id == model.Id).FirstOrDefault(); if (item != null) { item.Status = (byte)Commons.EStatus.Deleted; item.UpdatedBy = model.UpdatedBy; item.UpdatedDate = DateTime.Now; cxt.SaveChanges(); } } }
public bool Insert(UnitOfMeasureModel model, ref string msg) { bool result = true; using (NuWebContext cxt = new NuWebContext()) { try { //if (cxt.I_UnitOfMeasure.Where(xx => xx.Code == model.Code).Select(ss => ss.Code).SingleOrDefault() != null) //{ // msg = "UOM code already exist, please input another one!"; // return false; //} var itemExsit = cxt.I_UnitOfMeasure.Any(x => x.Code.ToLower().Equals(model.Code.ToLower()) && x.Status != (int)Commons.EStatus.Deleted && x.OrganizationId == model.OrganizationId); if (itemExsit) { msg = _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("UOM Code") + " [" + model.Code + "] " + _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("is duplicated"); return(false); } if (string.IsNullOrEmpty(model.Name)) { model.Name = model.Code; } I_UnitOfMeasure item = new I_UnitOfMeasure(); item.Id = Guid.NewGuid().ToString(); item.Code = model.Code; item.Name = model.Name; item.IsActive = model.IsActive; item.CreatedBy = model.CreatedBy; item.CreatedDate = model.CreatedDate; item.UpdatedBy = model.UpdatedBy; item.UpdatedDate = model.UpdatedDate; item.OrganizationId = model.OrganizationId; item.Description = model.Description; item.Status = (int)Commons.EStatus.Actived; cxt.I_UnitOfMeasure.Add(item); cxt.SaveChanges(); } catch (Exception ex) { _logger.Error(ex); } } return(result); }
public bool Insert(List <DateOfWeeksModels> lstInfo) { bool result = true; var info = lstInfo.FirstOrDefault(); using (NuWebContext cxt = new NuWebContext()) { using (var transaction = cxt.Database.BeginTransaction()) { try { List <G_DateOfWeeks> lstInsert = new List <G_DateOfWeeks>(); G_DateOfWeeks itemInsert = null; foreach (var item in lstInfo) { itemInsert = new G_DateOfWeeks(); itemInsert.Id = Guid.NewGuid().ToString(); itemInsert.DayNumber = item.DayNumber; itemInsert.DayName = item.DayName; itemInsert.CreatedDate = item.CreatedDate; itemInsert.CreatedUser = item.CreatedUser; itemInsert.LastUserModified = item.LastUserModified; itemInsert.LastDateModified = item.LastDateModified; lstInsert.Add(itemInsert); } cxt.G_DateOfWeeks.AddRange(lstInsert); cxt.SaveChanges(); transaction.Commit(); } catch (Exception ex) { _logger.Error(ex); result = false; transaction.Rollback(); } finally { if (cxt != null) { cxt.Dispose(); } } } } //var jsonContent = JsonConvert.SerializeObject(lstInfo); //_baseFactory.InsertTrackingLog("G_DateOfWeeks", jsonContent, "DateOfWeeksId", result); return(result); }