public Entities.TimeZone Update(Entities.TimeZone timeZoneParam) { var timeZone = _context.TimeZones.Find(timeZoneParam.Id); if (timeZone == null) { throw new AppException("Time zone not found"); } if (string.IsNullOrWhiteSpace(timeZone.Name) || string.IsNullOrWhiteSpace(timeZone.City)) { throw new AppException("Name and/or City cannot be null"); } if (timeZoneParam.DifferenceToGMT % 0.25 == 0 && timeZoneParam.DifferenceToGMT > -13 && timeZoneParam.DifferenceToGMT < 15) { timeZone.DifferenceToGMT = timeZoneParam.DifferenceToGMT; } timeZone.Name = timeZoneParam.Name; timeZone.City = timeZoneParam.City; timeZone.DifferenceToGMT = timeZoneParam.DifferenceToGMT; _context.TimeZones.Update(timeZone); _context.SaveChanges(); return(timeZone); }
public List <Entities.TimeZone> RetrieveAll() { SqlCommand command = null; SqlDataAdapter adapter = null; try { command = mDbConnection.CreateCommand(); command.CommandText = "RetrieveAllTimeZones"; command.CommandType = CommandType.StoredProcedure; adapter = new SqlDataAdapter(command); DataTable TimeZoneDataTable = new DataTable("TimeZone"); adapter.Fill(TimeZoneDataTable); //create a List List <Entities.TimeZone> TimeZones = null; if (TimeZoneDataTable.Rows.Count > 0) { TimeZones = new List <Entities.TimeZone>(); } // Iterate each row. foreach (DataRow row in TimeZoneDataTable.Rows) { // Create an instance of TimeZones. Entities.TimeZone timezone = new Entities.TimeZone(Int32.Parse(row["TimeZoneId"].ToString())); timezone.Name = row["Name"].ToString(); timezone.ShortName = row["ShortName"].ToString(); timezone.Description = row["Description"].ToString(); timezone.Reason = row["Reason"].ToString(); timezone.IsActive = bool.Parse(row["IsActive"].ToString()); timezone.LastUpdateUserId = Int32.Parse(row["LastUpdateUserId"].ToString()); timezone.LastUpdateDate = DateTime.Parse(row["LastUpdateDate"].ToString()); // Add to the List TimeZones.Add(timezone); } // Return the list. return(TimeZones); } catch { throw; } finally { // Dispose. if (adapter != null) { adapter.Dispose(); } if (command != null) { command.Dispose(); } } }
public Entities.TimeZone Create(Entities.TimeZone timeZone) { if (_context.TimeZones.Any(x => x.Id == timeZone.Id)) { throw new AppException("TimeZone \"" + timeZone.Id + "\" is already taken"); } if (string.IsNullOrWhiteSpace(timeZone.Name) || string.IsNullOrWhiteSpace(timeZone.City)) { throw new AppException("Name and/or City cannot be null"); } if (timeZone.DifferenceToGMT % 0.25 != 0 && timeZone.DifferenceToGMT < -12 && timeZone.DifferenceToGMT > 14) { throw new AppException("DifferenceToGMT \"" + timeZone.DifferenceToGMT + "\" should be a multiple of 0.25"); } _context.TimeZones.Add(timeZone); _context.SaveChanges(); return(timeZone); }
public void CreateDomainLevel1() { try { var ctx = ApplicationDbContext.Create(); //already OK if (ctx.Campaigns.Any()) { return; } var reader = new ReadOnlyContext(); var db = MemoryDB.LoadDomainLevel1(reader); var container = new MemoryDB(); foreach (var item in db.Campaigns) { var campaign = new Campaign { Id = item.Id, //AccountManager = accountManager, //AccountManagerId = accountManager?.Id, AccountManagerId = item.AccountManagerId, //Client = client, //ClientId = client?.Id, ClientId = item.ClientId, ActiveControl = item.ActiveControl, BillingPH = item.BillingPH, CampaignLimit = item.CampaignLimit, CompanyLink = item.CompanyLink, CreationDate = item.CreationDate, Description = item.Description, Identifier = item.Identifier, IsDeleted = item.IsDeleted, LastUpdate = item.LastUpdate, MaxAttempt = item.MaxAttempt, Objective = item.Objective, SpellCheck = item.SpellCheck, }; container.Campaigns.Add(campaign); } foreach (var item in db.Projects) { var project = new Project { Id = item.Id, //Campaign = campaign, //CampaignId = campaign.Id, CampaignId = item.CampaignId, CreationDate = item.CreationDate, Description = item.Description, IsDeleted = item.IsDeleted, LastUpdate = item.LastUpdate, Name = item.Name, Priority = item.Priority, }; container.Projects.Add(project); } foreach (var item in db.TimeZones) { var timeZone = new Entities.TimeZone { Id = item.Id, Code = item.Code, CreationDate = item.CreationDate, CurrentTime = item.CurrentTime, DST = item.DST, IsDeleted = item.IsDeleted, LastUpdate = item.LastUpdate, Name = item.Name, STD = item.STD, }; container.TimeZones.Add(timeZone); } foreach (var item in db.Penalties) { var penalty = new Penalty { Id = item.Id, CreationDate = item.CreationDate, From = item.From, IsDeleted = item.IsDeleted, LastUpdate = item.LastUpdate, PayRate = item.PayRate, PenaltyFee = item.PenaltyFee, To = item.To, }; container.Penalties.Add(penalty); } foreach (var item in db.AlertSettings) { var alertSettings = new AlertSettings { Id = item.Id, LastUpdate = item.LastUpdate, CreationDate = item.CreationDate, DataPercentage = item.DataPercentage, IsDeleted = item.IsDeleted, NotificationEmails = item.NotificationEmails, }; container.AlertSettings.Add(alertSettings); } foreach (var item in db.AreaCodes) { var areaCode = new AreaCode { Id = item.Id, //TimeZone = timeZone, //TimeZoneId = timeZone.Id, TimeZoneId = item.TimeZoneId, CreationDate = item.CreationDate, IsDeleted = item.IsDeleted, LastUpdate = item.LastUpdate, Name = item.Name, TZ = item.TZ, }; container.AreaCodes.Add(areaCode); } foreach (var item in db.CallCodes) { var campaign = container.Campaigns .SingleOrDefault(x => x.Id == item.CampaignId); var callCode = new CallCode( campaign, item.Name, item.Code, item.Behavior, item.IsSuccess, item.CreationDate); callCode.IsDeleted = item.IsDeleted; container.CallCodes.Add(callCode); } foreach (var item in db.ExportSettings) { var exportSettings = new ExportSettings { Id = item.Id, //NOT FK CampaignId = item.CampaignId, CreationDate = item.CreationDate, IsDeleted = item.IsDeleted, Key = item.Key, LastUpdate = item.LastUpdate, Name = item.Name, Value = item.Value, }; container.ExportSettings.Add(exportSettings); } foreach (var item in db.ProjectPriorities) { var projectPriority = new ProjectPriority { Id = item.Id, //Project = item.Project, //ProjectId = project.Id, ProjectId = item.ProjectId, LastUpdate = item.LastUpdate, IsDeleted = item.IsDeleted, CreationDate = item.CreationDate, Field = item.Field, PriorityValue = item.PriorityValue, }; container.ProjectPriorities.Add(projectPriority); } foreach (var item in db.ProjectPriorityDetails) { var projectPriorityDetail = new ProjectPriorityDetail { Id = item.Id, //ProjectPriority = projectPriority, //ProjectPriorityId = projectPriority.Id, ProjectPriorityId = item.ProjectPriorityId, CreationDate = item.CreationDate, FieldPriorityValue = item.FieldPriorityValue, FieldValue = item.FieldValue, IsDeleted = item.IsDeleted, LastUpdate = item.LastUpdate, }; container.ProjectPriorityDetails.Add(projectPriorityDetail); } foreach (var item in db.StateRestrictions) { var stateRestriction = new StateRestriction { Id = item.Id, //TimeZone = timeZone, //TimeZoneId = timeZone.Id, TimeZoneId = item.TimeZoneId, LastUpdate = item.LastUpdate, IsDeleted = item.IsDeleted, Abbreviation = item.Abbreviation, CreationDate = item.CreationDate, IsRestricted = item.IsRestricted, Name = item.Name, }; container.StateRestrictions.Add(stateRestriction); } foreach (var item in db.OnWatchSettings) { var onWatchSettings = new OnWatchSettings { Id = item.Id, //Campaign = campaign, //CampaignId = campaign.Id, CampaignId = item.CampaignId, CreationDate = item.CreationDate, HoursLeft = item.HoursLeft, IsDeleted = item.IsDeleted, LastUpdate = item.LastUpdate, }; container.OnWatchSettings.Add(onWatchSettings); } ctx.Campaigns.AddRange(container.Campaigns); ctx.Projects.AddRange(container.Projects); ctx.TimeZones.AddRange(container.TimeZones); ctx.Penalties.AddRange(container.Penalties); ctx.AlertSettings.AddRange(container.AlertSettings); ctx.AreaCodes.AddRange(container.AreaCodes); ctx.CallCodes.AddRange(container.CallCodes); ctx.ExportSettings.AddRange(container.ExportSettings); ctx.ProjectPriorities.AddRange(container.ProjectPriorities); ctx.ProjectPriorityDetails.AddRange(container.ProjectPriorityDetails); ctx.StateRestrictions.AddRange(container.StateRestrictions); ctx.SaveChanges(); } catch (Exception ex) { var str = ex.ToString(); System.Diagnostics.Debug.WriteLine(str); } }
public List <Entities.TimeZone> Retrieve(int[] ids) { SqlCommand command = null; SqlDataAdapter adapter = null; try { StringBuilder xml = new StringBuilder(); xml.Append("<TimeZones>"); foreach (int id in ids) { xml.Append(String.Format("<TimeZone><Id>{0}</Id></TimeZone>", id)); } xml.Append("</TimeZones>"); command = mDbConnection.CreateCommand(); command.CommandText = "RetrieveTimeZones"; command.CommandType = CommandType.StoredProcedure; command.Parameters.Add("@data", SqlDbType.Xml).Value = xml.ToString(); adapter = new SqlDataAdapter(command); DataTable TimeZoneDataTable = new DataTable("TimeZone"); adapter.Fill(TimeZoneDataTable); //create a List List <Entities.TimeZone> TimeZones = new List <Entities.TimeZone>(); // Iterate each row. foreach (DataRow row in TimeZoneDataTable.Rows) { // Create an instance of TimeZones. Entities.TimeZone timezone = new Entities.TimeZone(Int32.Parse(row["TimeZoneId"].ToString())); timezone.Name = row["Name"].ToString(); timezone.ShortName = row["ShortName"].ToString(); timezone.Description = row["Description"].ToString(); timezone.Reason = row["Reason"].ToString(); timezone.IsActive = bool.Parse(row["IsActive"].ToString()); if (timezone.LastUpdateUserId >= 0) { timezone.LastUpdateUserId = Int32.Parse(row["LastUpdateUserId"].ToString()); } if (timezone.LastUpdateDate != null) { timezone.LastUpdateDate = DateTime.Parse(row["LastUpdateDate"].ToString()); } timezone.CustomData.Add("LastUpdateUserName", row["LastUpdateUserName"].ToString()); // Add to the List TimeZones.Add(timezone); } // Return the list. return(TimeZones); } catch { throw; } finally { // Dispose. if (adapter != null) { adapter.Dispose(); } if (command != null) { command.Dispose(); } } }
public List <Entities.TimeZone> Search(SearchCriteria criteria) { SqlCommand command = null; SqlDataAdapter adapter = null; try { //create a instance of sqlcommand command = mDbConnection.CreateCommand(); command.CommandText = "SearchTimeZones"; command.CommandType = CommandType.StoredProcedure; command.Parameters.Add("@Data", SqlDbType.Xml).Value = criteria.GetXml(); //create a instanse of SqlAdapter adapter = new SqlDataAdapter(command); //create a instance of Datatable DataTable TimeZoneDatatable = new DataTable(); adapter.Fill(TimeZoneDatatable); //create a List List <Entities.TimeZone> TimeZones = new List <Entities.TimeZone>(); // Iterate each row. foreach (DataRow row in TimeZoneDatatable.Rows) { // Create an instance of Role. Entities.TimeZone timezone = new Entities.TimeZone(Int32.Parse(row["TimeZoneId"].ToString())); timezone.Name = row["Name"].ToString(); timezone.ShortName = row["ShortName"].ToString(); timezone.Description = row["Description"].ToString(); timezone.Reason = row["Reason"].ToString(); timezone.IsActive = bool.Parse(row["IsActive"].ToString()); if (timezone.LastUpdateUserId >= 0) { timezone.LastUpdateUserId = Int32.Parse(row["LastUpdateUserId"].ToString()); } if (timezone.LastUpdateDate != null) { timezone.LastUpdateDate = DateTime.Parse(row["LastUpdateDate"].ToString()); } timezone.CustomData.Add("LastUpdateUserName", row["LastUpdateUserName"].ToString()); // Add to the List TimeZones.Add(timezone); } // Return the list. return(TimeZones); } catch { throw; } finally { // Dispose. if (adapter != null) { adapter.Dispose(); } if (command != null) { command.Dispose(); } } }
public void Update(Entities.TimeZone entity) { SqlCommand command = null; SqlDataAdapter adapter = null; SqlTransaction transaction = null; try { command = mDbConnection.CreateCommand(); command.CommandText = "UpdateTimeZones"; command.CommandType = CommandType.StoredProcedure; command.Parameters.Add("@DataXml", SqlDbType.Xml).Value = entity.GetXml(); command.Parameters.Add("@hasError", SqlDbType.Bit).Direction = ParameterDirection.Output; // execute transaction = mDbConnection.BeginTransaction(); command.Transaction = transaction; // fill error datatable adapter = new SqlDataAdapter(command); DataTable errorDataTable = new DataTable(); adapter.Fill(errorDataTable); // commit transaction.Commit(); // Get output parameters. bool hasError = bool.Parse(command.Parameters["@hasError"].Value.ToString()); if (hasError) { // Create exception instance. //ValidationException exception = new ValidationException("Validation error(s) occurred."); ValidationException exception = new ValidationException(""); if (errorDataTable != null) { StringBuilder message = new StringBuilder(); foreach (DataRow row in errorDataTable.Rows) { message.Append(string.Format("{0}", row["Value"].ToString())); } exception.Data.Add("IsExists", message); } throw exception; } } catch (ValidationException ve) { throw ve; } catch { if (transaction != null) { if (transaction.Connection != null) { transaction.Rollback(); } } throw; } finally { // Dispose. if (adapter != null) { adapter.Dispose(); } if (transaction != null) { adapter.Dispose(); } if (command != null) { command.Dispose(); } } }