public override bool DeleteData(int userId, int id, out Notification notification) { notification = new Notification(); notification.Type = NotificationType.Success; try { using (CompanyBranchMngEntities context = CreateContext()) { Company dbCompany = context.Company.FirstOrDefault(o => o.CompanyID == id); if (dbCompany == null) { notification.Type = NotificationType.Error; notification.Message = "Can not find data"; return(false); } context.Company.Remove(dbCompany); context.SaveChanges(); // refresh cache Library.CacheHelper.ClearCache("SUPPORT_INTERNAL_COMPANY"); return(true); } } catch (Exception ex) { notification.Type = NotificationType.Error; notification.Message = Library.Helper.GetInnerException(ex).Message; return(false); } }
public override bool UpdateData(int userId, int id, ref object dtoItem, out Notification notification) { notification = new Notification(); notification.Type = NotificationType.Success; try { CompanyDTO dtoCompany = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <CompanyDTO>(); using (CompanyBranchMngEntities context = CreateContext()) { Company dbCompany; if (id > 0) { dbCompany = context.Company.FirstOrDefault(o => o.CompanyID == id); } else { dbCompany = new Company(); context.Company.Add(dbCompany); } if (dbCompany == null) { notification.Type = NotificationType.Error; notification.Message = "Can not find data"; return(false); } if (dtoCompany.HasChanged) { Framework.DAL.DataFactory framworkFactory = new Framework.DAL.DataFactory(); dtoCompany.Logo = framworkFactory.CreateFilePointer(FrameworkSetting.Setting.AbsoluteUserTempFolder + userId.ToString() + @"\", dtoCompany.NewFile, dtoCompany.Logo); } dataConverter.DTO2DB_Company(dtoCompany, ref dbCompany); dbCompany.UpdatedBy = userId; dbCompany.UpdatedDate = DateTime.Now; context.Branch.Local.Where(o => o.Company == null).ToList().ForEach(o => context.Branch.Remove(o)); context.SaveChanges(); // refresh cache Library.CacheHelper.ClearCache("SUPPORT_INTERNAL_COMPANY"); dtoItem = GetData(userId, dbCompany.CompanyID, new Hashtable(), out notification); } return(true); } catch (Exception ex) { notification.Type = NotificationType.Error; notification.Message = Library.Helper.GetInnerException(ex).Message; return(false); } }