public void Create(long campaignID, string siteIDs) { try { string deact = string.Format("UPDATE SiteCampaign SET Active=0 WHERE CampaignID={0}", campaignID); _context.ExecuteTSQL(deact); //create new if (!string.IsNullOrEmpty(siteIDs)) { foreach (var siteid in siteIDs.TrimEnd(',').Split(',').ToArray()) { SiteCampaign siteCampaign = new SiteCampaign() { SiteID = Convert.ToInt64(siteid), CampaignID = campaignID, Active = true }; _context.Add <SiteCampaign>(siteCampaign); _context.SaveChanges(); } } } catch (Exception ex) { throw new ArgumentException("Unexpected error encountered. Please contact your system administrator.", ex.InnerException); } }
public LoBViewModel Create(LoBViewModel model) { if (string.IsNullOrEmpty(model.SiteCampaignIds.Trim())) { var dataExists = _context.AsQueryable <LoB>().Where(x => x.Name == model.Name && x.CampaignID == model.CampaignID && x.Active == true).FirstOrDefault(); if (dataExists != null) { throw new ArgumentException("LoB name already exists in campaign."); } } var data = new LoB() { CampaignID = model.CampaignID, Name = model.Name, Code = model.Code, Description = model.Description, CreatedBy = model.CreatedBy, ModifiedBy = null, DateCreated = model.DateCreated, DateModified = null, Active = model.Active }; _context.Add <LoB>(data); _context.SaveChanges(); model.ID = data.ID; return(model); }
public ModuleViewModel Create(ModuleViewModel model) { var dataExists = _context.AsQueryable <Module>().Where(x => x.Name == model.Name && x.ParentID == model.ParentID).FirstOrDefault(); if (dataExists != null) { throw new ArgumentException("Module name already exists in it's parent."); } var data = new Module() { ParentID = model.ParentID, Name = model.Name, Route = model.Route, SortOrder = model.SortOrder, CreatedBy = model.CreatedBy, ModifiedBy = null, DateCreated = model.DateCreated, DateModified = null, Active = model.Active }; _context.Add <Module>(data); _context.SaveChanges(); model.ID = data.ID; return(model); }
public ModuleRolePermissionViewModel Create(ModuleRolePermissionViewModel model) { var dataExists = _context.AsQueryable <ModuleRolePermission>().Where(x => x.ModuleID == model.ModuleID && x.RoleID == model.RoleID && x.PermissionID == model.PermissionID && x.Active == true).FirstOrDefault(); if (dataExists != null) { throw new ArgumentException("Permission mapping already exists."); } var data = new ModuleRolePermission() { ModuleID = model.ModuleID, RoleID = model.RoleID, PermissionID = model.PermissionID, CreatedBy = model.CreatedBy, ModifiedBy = null, DateCreated = model.DateCreated, DateModified = null, Active = model.Active }; _context.Add <ModuleRolePermission>(data); _context.SaveChanges(); model.ID = data.ID; return(model); }
public RoleViewModel Create(RoleViewModel model) { var dataExists = _context.AsQueryable <Role>().Where(x => x.Name == model.Name && x.Active == true).FirstOrDefault(); if (dataExists != null) { throw new ArgumentException("Role name already exists in campaign."); } var data = new Role() { Name = model.Name, Code = model.Code, Description = model.Description, CreatedBy = model.CreatedBy, ModifiedBy = null, DateCreated = model.DateCreated, DateModified = null, Active = model.Active }; _context.Add <Role>(data); _context.SaveChanges(); model.ID = data.ID; return(model); }
public UserRoleViewModel Create(UserRoleViewModel model) { //check if data exists var dataExists = _context.AsQueryable <UserRole>().Where(x => x.NTLogin == model.NTLogin && x.EmployeeID == model.EmployeeID && x.Active == true).FirstOrDefault(); if (dataExists != null) { this.Deactivate(dataExists.ID, model.ModifiedBy); } //create data var data = new UserRole() { RoleID = (long)model.RoleID, NTLogin = model.NTLogin, EmployeeID = model.EmployeeID, CreatedBy = model.CreatedBy, ModifiedBy = null, DateCreated = model.DateCreated, DateModified = null, Active = model.Active ?? true }; _context.Add <UserRole>(data); _context.SaveChanges(); model.ID = data.ID; return(model); }
public PermissionViewModel Create(PermissionViewModel model) { var dataExists = _context.AsQueryable <Permission>().Where(x => x.Name == model.Name).FirstOrDefault(); if (dataExists != null) { throw new ArgumentException("Permission name already exists in site."); } var data = new Permission() { Name = model.Name, Description = model.Description, CreatedBy = model.CreatedBy, ModifiedBy = null, DateCreated = model.DateCreated, DateModified = null, Active = model.Active }; _context.Add <Permission>(data); _context.SaveChanges(); model.ID = data.ID; return(model); }
public SiteCampaignLobFormulaViewModel Create(SiteCampaignLobFormulaViewModel model) { //check if exists var origData = this.Get(model.SiteID, model.CampaignID, model.LoBID, null, true); if (origData.Count() > 0) { throw new ArgumentException("Insert failed. Mapping already exists."); } var data = new SiteCampaignLobFormula() { SiteID = model.SiteID, CampaignID = model.CampaignID, LoBID = model.LoBID, DynamicFormulaID = model.DynamicFormulaID, DateCreated = DateTime.Now, DateModified = null, Active = true }; _context.Add <SiteCampaignLobFormula>(data); _context.SaveChanges(); model.ID = data.ID; return(model); }
public SiteCampaignLoBViewModel Create(SiteCampaignLoBViewModel model) { try { SiteCampaignLoB data = new SiteCampaignLoB() { SiteID = model.SiteID, CampaignID = model.CampaignID, LoBID = model.LobID, Active = model.Active }; _context.Add <SiteCampaignLoB>(data); _context.SaveChanges(); model.ID = data.ID; return(model); } catch (Exception ex) { throw new ArgumentException("Unexpected error encountered. Please contact yours system Adminsitrator.", ex.InnerException); } }
public void Save(ref SiteCampaignLobFormulaViewModel model) { var data = _context.Add <SiteCampaignLobFormula>(new SiteCampaignLobFormula() { SiteID = model.SiteID, CampaignID = model.CampaignID, LoBID = model.LoBID, DynamicFormulaID = model.DynamicFormulaID, DateCreated = model.DateCreated, Active = model.Active }); _context.SaveChanges(); model.ID = data.ID; }
public AuditTrailViewModel Create(AuditTrailViewModel model) { var data = new AuditTrail() { AuditEntry = model.AuditEntry, CreatedBy = model.CreatedBy, DateCreated = model.DateCreated, DateModified = null }; _context.Add <AuditTrail>(data); _context.SaveChanges(); model.ID = data.ID; return(model); }
public void Save(WeeklyDatapointViewModel model) { //check data if exists var orig = _context.AsQueryable <WeeklyDatapoint>() .Where(x => x.Date == model.Date && x.DatapointID == model.DatapointID && x.SiteID == model.SiteID && x.CampaignID == model.CampaignID && x.LoBID == model.LoBID) .FirstOrDefault(); WeeklyDatapoint data = new WeeklyDatapoint(); if (orig != null) { orig.Data = model.Data; orig.ModifiedBy = model.ModifiedBy; orig.DateModified = model.DateModified; _context.Update <WeeklyDatapoint>(orig); _context.SaveChanges(); } else { data = new WeeklyDatapoint() { SiteID = model.SiteID, CampaignID = model.CampaignID, LoBID = model.LoBID, DatapointID = model.DatapointID, Week = model.Week, Data = model.Data, Date = model.Date, CreatedBy = model.CreatedBy, ModifiedBy = null, DateCreated = model.DateCreated, DateModified = null }; _context.Add(data); _context.SaveChanges(); } }
public HiringDatapointViewModel Create(HiringDatapointViewModel model) { var dataExists = _context.AsQueryable <Data.Entities.HiringDatapoint>().Where(x => x.Name == model.Name && x.Active == true && x.SegmentID == model.SegmentID).FirstOrDefault(); if (dataExists != null) { throw new ArgumentException("Datapoint name already exists in segment."); } var sortOrder = 0; var lastData = _context.AsQueryable <Data.Entities.HiringDatapoint>().Where(x => x.Active == true && x.SegmentID == model.SegmentID).OrderByDescending(x => x.SortOrder).FirstOrDefault(); if (lastData != null) { sortOrder = lastData.SortOrder + 1; } var data = new Data.Entities.HiringDatapoint() { Name = model.Name, Datatype = model.Datatype, SegmentID = model.SegmentID, SortOrder = sortOrder, CreatedBy = model.CreatedBy, ModifiedBy = null, DateCreated = model.DateCreated ?? DateTime.Now, DateModified = null, Active = model.Active ?? true, Visible = model.Visible ?? true }; _context.Add <Data.Entities.HiringDatapoint>(data); _context.SaveChanges(); model.ID = data.ID; model.Active = data.Active; model.Visible = data.Visible; return(model); }
public SegmentCategoryViewModel Create(SegmentCategoryViewModel model) { var dataExists = _context.AsQueryable <Data.Entities.SegmentCategory>().Where(x => x.Name == model.Name && x.Active == true).FirstOrDefault(); if (dataExists != null) { throw new ArgumentException("Segment Category name already exists in campaign."); } var sortOrder = 0; var lastData = _context.AsQueryable <Data.Entities.SegmentCategory>().Where(x => x.Active == true).LastOrDefault(); if (lastData != null) { sortOrder = lastData.SortOrder + 1; } var data = new Data.Entities.SegmentCategory() { Name = model.Name, SortOrder = sortOrder, CreatedBy = model.CreatedBy, ModifiedBy = null, DateCreated = model.DateCreated ?? DateTime.Now, DateModified = null, Active = model.Active == null ? true : false, Visible = model.Visible == null ? true : false }; _context.Add <Data.Entities.SegmentCategory>(data); _context.SaveChanges(); model.ID = data.ID; model.Active = data.Active; model.Visible = data.Visible; return(model); }
public bool ExtractCSV(string filelocation, string ntLogin) { bool retValue = false; try { string filename = Path.GetFileNameWithoutExtension(filelocation); using (StreamReader sr = new StreamReader(filelocation)) { string currentLine; #region Setup Site, Campaign and LOB Id string[] siteCampaignLobIds = filename.Split('.'); int siteID = Convert.ToInt32(siteCampaignLobIds[0]); int campaignID = Convert.ToInt32(siteCampaignLobIds[1]); int lobID = Convert.ToInt32(siteCampaignLobIds[2]); #endregion #region Method Variable(s) string segmentName = string.Empty; int col = 0; int row = 0; int ctr = 0; // currentLine will be null when the StreamReader reaches the end of file Regex regx = new Regex(",(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))"); #endregion #region Deactivate existing Raw data in DB string procName = "wfmpcp_ActivateDeactiviateCSV_sp"; string[] parameters = { "Active", "SiteID", "CampaignID", "LoBID" }; object[] paramValues = { false, siteID, campaignID, lobID }; _context.Execute(procName, parameters, paramValues); #endregion #region Read CSV while ((currentLine = sr.ReadLine()) != null) { string[] splitted = regx.Split(currentLine); #region Iterate CSV Values foreach (var data in splitted) { col++; ctr++; string value = data.Replace("%", "").Replace("#VALUE!", "").Replace("#DIV/0!", "") .Replace("-", "").Trim(); #region Setup Date if (row == 1 && col > 2) { //Header string[] splittedDate = data.Trim().Split('/'); string mm = splittedDate[0].ToString().Trim().Length == 1 ? ("0" + splittedDate[0].ToString()) : splittedDate[0].ToString().Trim(); string dd = splittedDate[1].ToString().Trim().Length == 1 ? ("0" + splittedDate[1].ToString()) : splittedDate[1].ToString().Trim(); string yyyy = splittedDate[2].ToString(); value = string.Format("{0}-{1}-{2}", yyyy, mm, dd); } #endregion #region Just to add value to segment column if (col == 1) { if (!string.IsNullOrEmpty(value)) { segmentName = value; } value = segmentName; row++; } #endregion if (string.IsNullOrEmpty(value)) { value = "0"; } #region Insert New Record procName = "wfmpcp_CreateCSVRawData_sp"; parameters = new string[] { "Data", "CreatedBy", "RowNumber", "ColumnNumber", "SiteID", "CampaignID", "LoBID", "Filename" }; paramValues = new object[] { value.Replace(",", "").Replace("\"", "").Replace("`", "").Trim(), ntLogin, row, col, siteID, campaignID, lobID, string.Format("{0}.csv", filename) }; _context.Execute(procName, parameters, paramValues); #endregion if (col == 46) { col = 0; //reset col value } } #endregion } #endregion #region Setup Values to save //delete first to staging procName = "wfmpcp_DeleteStagingAHWeeklyDatapoint_sp"; parameters = new string[] { "SiteID", "CampaignID", "LobID" }; paramValues = new object[] { siteID, campaignID, lobID }; _context.Execute(procName, parameters, paramValues); //get data from csv #endregion Create Dataset #region Insert data to Staging table procName = "wfmpcp_CreateStagingWeeklyAHDatapoint_sp"; parameters = new string[] { "SiteID", "CampaignID", "LoBID", "Active" }; paramValues = new object[] { siteID, campaignID, lobID, true }; _context.Execute(procName, parameters, paramValues); #endregion #region Save data to WeeklyAHDatapoint and It's corresponding tables procName = "wfmpcp_SaveAHCStagingToActual_sp"; parameters = new string[] { "SiteID", "CampaignID", "LoBID" }; paramValues = new object[] { siteID, campaignID, lobID }; _context.Execute(procName, parameters, paramValues); #endregion #region Log to Audit Trail string entry = string.Empty; entry = string.Format("UploadAHCServce.ExtractCSV({0},{1});SiteID:{2};Campaign:{3};LoBID:{4};SUCCESS;", filelocation, ntLogin, siteID, campaignID, lobID); AuditTrail model = new AuditTrail() { AuditEntry = entry, CreatedBy = "System Generated", DateCreated = DateTime.Now, DateModified = DateTime.Now }; _context.Add <AuditTrail>(model); _context.SaveChanges(); #endregion retValue = true; sr.Dispose(); } } catch (Exception ex) { retValue = false; string entry = string.Empty; entry = string.Format("UploadAHCServce.ExtractCSV({0},{1});Error:{2};FAIL;", filelocation, ntLogin, ex.Message); AuditTrail model = new AuditTrail() { AuditEntry = entry, CreatedBy = "System Generated", DateCreated = DateTime.Now, DateModified = DateTime.Now }; _context.Add <AuditTrail>(model); _context.SaveChanges(); } return(retValue); }