public bool AddZone(ManageZoneAdd manageZone, TaxiAppzDBContext context, LoggedInUser loggedInUser) { var serviceExist = context.TabServicelocation.FirstOrDefault(t => t.IsDeleted == 0 && t.Servicelocid == manageZone.Serviceslocid); if (serviceExist == null) { throw new DataValidationException($"Service location does not already exists."); } TabZone tabZone = new TabZone(); tabZone.Zonename = manageZone.ZoneName; tabZone.Servicelocid = manageZone.Serviceslocid; tabZone.Unit = manageZone.Unit; tabZone.IsActive = 1; tabZone.IsDeleted = 0; tabZone.CreatedBy = tabZone.UpdatedBy = loggedInUser.UserName; tabZone.CreatedAt = tabZone.UpdatedAt = Extention.GetDateTime(); context.TabZone.Add(tabZone); context.SaveChanges(); foreach (var zonepolygon in manageZone.ZonePolygoneList) { TabZonepolygon tabZonepolygon = new TabZonepolygon(); tabZonepolygon.Longitudes = zonepolygon.Lng; tabZonepolygon.Latitudes = zonepolygon.Lat; tabZonepolygon.IsActive = 1; tabZonepolygon.CreatedBy = tabZonepolygon.UpdatedBy = loggedInUser.UserName; tabZonepolygon.CreatedAt = tabZonepolygon.UpdatedAt = Extention.GetDateTime(); tabZonepolygon.Zoneid = tabZone.Zoneid; context.TabZonepolygon.Add(tabZonepolygon); } context.SaveChanges(); return(true); }
public bool EditRole(TaxiAppzDBContext context, long id, Roles roles, LoggedInUser loggedInUser) { var roleExist = context.TabRoles.FirstOrDefault(t => t.IsDelete == 0 && t.RoleName.ToLower() == roles.RoleName.ToLower() && t.Roleid != id); if (roleExist != null) { throw new DataValidationException($"Role with name '{roles.RoleName}' already exists."); } TabRoles Insertdata = new TabRoles(); var updatedate = context.TabRoles.Where(r => r.Roleid == id && r.IsDelete == 0).FirstOrDefault(); if (updatedate != null) { updatedate.RoleName = roles.RoleName; updatedate.DisplayName = roles.DisplayName; updatedate.Description = roles.Description; updatedate.CreatedBy = loggedInUser.Email; updatedate.UpdatedAt = Extention.GetDateTime(); context.Update(updatedate); context.SaveChanges(); return(true); } return(false); }
public bool SaveSurgePrice(SurgePrice surgePrice, TaxiAppzDBContext content, LoggedInUser loggedIn) { var existZone = content.TabZone.FirstOrDefault(t => t.IsDeleted == 0 && t.Zoneid == surgePrice.Zoneid); if (existZone == null) { throw new DataValidationException("Zone name does not exist"); } var exist = content.TabSurgeprice.FirstOrDefault(t => t.IsDelete == false && t.ZoneId == surgePrice.Zoneid); if (exist == null) { TabSurgeprice tabSurgeprice = new TabSurgeprice(); tabSurgeprice.PeakType = surgePrice.Peaktype; tabSurgeprice.StartTime = surgePrice.Starttime; tabSurgeprice.ZoneId = surgePrice.Zoneid; tabSurgeprice.EndTime = surgePrice.Endtime; tabSurgeprice.SurgepriceType = surgePrice.Surgepricetype; tabSurgeprice.SurgepriceValue = surgePrice.Surgepricevalue; tabSurgeprice.IsActive = true; tabSurgeprice.UpdatedAt = tabSurgeprice.CreatedAt = Extention.GetDateTime(); tabSurgeprice.UpdatedBy = tabSurgeprice.CreatedBy = loggedIn.UserName; content.TabSurgeprice.Add(tabSurgeprice); content.SaveChanges(); return(true); } else { exist.PeakType = surgePrice.Peaktype; exist.StartTime = surgePrice.Starttime; exist.EndTime = surgePrice.Endtime; exist.SurgepriceType = surgePrice.Surgepricetype; exist.SurgepriceValue = surgePrice.Surgepricevalue; exist.UpdatedAt = Extention.GetDateTime(); exist.UpdatedBy = loggedIn.UserName; content.TabSurgeprice.Update(exist); content.SaveChanges(); return(true); } }