protected DriverLogin IsTokenValid(RequestTypeEnum requestType) { var requestParams = Request.GetQueryNameValuePairs().ToList(); if (requestParams.Count(x => x.Key.Equals("AuthToken")) == 0) { throw new Exception("Authentication token is required."); } string authToken = requestParams.FirstOrDefault(x => x.Key.Equals("AuthToken")).Value; var driverLogin = db.DriverLogins.FirstOrDefault(x => x.Token == authToken); if (driverLogin == null) { throw new Exception("Authentication token is invalid."); } db.APIRequestLogs.Add(new APIRequestLog() { Id = Guid.NewGuid(), CreatedAt = DateTime.Now, RequestType = (int)requestType, }); db.SaveChanges(); return(driverLogin); }
public void AddClaim(WFPICTContext ctx, string roleId, Guid claimID) { ctx.RoleClaims.Add(new AspNetRoleClaims() { Id = Guid.NewGuid(), RoleID = roleId, ClaimID = claimID, CreatedAt = DateTime.Now }); ctx.SaveChanges(); }
/// <summary> /// Save changes in the current DbContext /// </summary> public int SaveChanges() { int retValue; try { SaveChangesSuccess = true; retValue = _dbContext.SaveChanges(); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); SaveChangesSuccess = false; retValue = 0; } return(retValue); }
public static void Seed(WFPICTContext context) { #region Order Guid typeID = Guid.NewGuid(); // Piano Types foreach (var ptype in EnumHelper.GetEnumTextValues(typeof(PianoTypeEnum))) { var already = context.PianoTypes.FirstOrDefault(m => m.Code == ptype.Value); if (already == null) { context.PianoTypes.Add(new PianoType() { Id = ptype.Text == "Spinet" ? typeID : Guid.NewGuid(), CreatedAt = DateTime.Now, Code = ptype.Value, Type = ptype.Text, }); } } context.SaveChanges(); //Piano Make foreach (var ptype in EnumHelper.GetEnumTextValues(typeof(PianoMakeEnum))) { var already = context.PianoMake.FirstOrDefault(m => m.Name == ptype.Text); if (already == null) { context.PianoMake.Add(new PianoMake() { Id = Guid.NewGuid(), Code = ptype.Value, Name = ptype.Text, CreatedAt = DateTime.Now, }); } } context.SaveChanges(); // Piano Finish foreach (var finish in EnumHelper.GetEnumTextValues(typeof(PianoFinishEnum))) { var already = context.PianoFinish.FirstOrDefault(m => m.Code == finish.Value); if (already == null) { context.PianoFinish.Add(new PianoFinish() { Id = Guid.NewGuid(), Code = finish.Value, Name = finish.Text, CreatedAt = DateTime.Now, }); } } context.SaveChanges(); //PianoSizes context.PianoSize.Add(new PianoSize() { Id = Guid.NewGuid(), PianoTypeId = typeID, Width = 235.56, CreatedAt = DateTime.Now, }); context.SaveChanges(); context.PianoSize.Add(new PianoSize() { Id = Guid.NewGuid(), PianoTypeId = typeID, Width = 180.34, CreatedAt = DateTime.Now, }); context.SaveChanges(); // Piano Charges int code = 100; foreach (var ptype in EnumHelper.GetEnumTextValues(typeof(ChargesTypeEnum))) { string officeCode = ptype.Value; var already = context.PianoCharges.FirstOrDefault(m => m.Details.ToString() == officeCode); if (already == null) { var rnd = new Random(DateTime.Now.Millisecond); context.PianoCharges.Add(new PianoCharges() { Id = Guid.NewGuid(), CreatedAt = DateTime.Now, Code = code.ToString(), Details = ptype.Text, Amount = rnd.Next(1000) }); code += 100; } } context.SaveChanges(); // Test Client var clientId = Guid.NewGuid(); var addressId = Guid.NewGuid(); context.Clients.Add(new Client() { Id = clientId, CreatedAt = DateTime.Now, ClientType = 1, AccountCode = "456343", Name = "Test Client 1", PhoneNumber = "12345678", EmailAddress = "*****@*****.**", Comment = "Its test Client", }); context.SaveChanges(); // Test Address context.Addresses.Add(new Address() { Id = addressId, CreatedAt = DateTime.Now, ClientId = clientId, Name = "Client Person Name", Address1 = "Complete Address", PhoneNumber = "1234", PostCode = "123", State = "CA", City = "City name", Lat = "34.504772", Lng = "-117.221566", }); context.SaveChanges(); var client = context.Clients.FirstOrDefault(); if (client != null) { client.AddressId = addressId; context.SaveChanges(); } #endregion #region Delivery // Vehicles Types var vehicleTypeId1 = Guid.NewGuid(); var vehicleTypeId2 = Guid.NewGuid(); context.VehicleTypes.Add(new VehicleType() { Id = vehicleTypeId1, CreatedAt = DateTime.Now, Code = "101", Name = "Truck", }); context.VehicleTypes.Add(new VehicleType() { Id = vehicleTypeId2, CreatedAt = DateTime.Now, Code = "102", Name = "Trailer", }); context.SaveChanges(); var vehicle1 = Guid.NewGuid(); var vehicle2 = Guid.NewGuid(); var vehicle3 = Guid.NewGuid(); context.Vehicles.Add(new Vehicle() { Id = vehicle1, CreatedAt = DateTime.Now, Code = "5876", Name = "Truck ABC", VehicleTypeId = vehicleTypeId1 }); context.Vehicles.Add(new Vehicle() { Id = vehicle2, CreatedAt = DateTime.Now, Code = "4272", Name = "Truck XYZ", VehicleTypeId = vehicleTypeId1 }); context.Vehicles.Add(new Vehicle() { Id = vehicle3, CreatedAt = DateTime.Now, Code = "633", Name = "Trailer X", VehicleTypeId = vehicleTypeId2 }); context.SaveChanges(); // Drivers context.Drivers.Add(new Driver() { Id = Guid.NewGuid(), CreatedAt = DateTime.Now, Code = "D101", Password = "******", Name = "Driver 1 Name", Description = "This is test Driver 1", }); context.Drivers.Add(new Driver() { Id = Guid.NewGuid(), CreatedAt = DateTime.Now, Code = "D102", Password = "******", Name = "Driver 2 Name", Description = "This is Driver 2", }); context.SaveChanges(); // Warehouse var warehouse = new Warehouse() { Id = Guid.NewGuid(), CreatedAt = DateTime.Now, Code = "W101", Name = "ENCORE PIANO MOVING Warehouse 101", Address1 = "15915 CANARY AVE.", PhoneNumber = "(714) 739-4717", PostCode = "90638", State = "CA", City = "LA MIRADA", Lat = "33.892162", Lng = "-118.024756" }; context.Warehouses.Add(warehouse); var locations = new string[] { "Los Angeles", "San Francisco", "Anaheim" }; foreach (var l in locations) { context.Locations.Add(new Location() { Id = Guid.NewGuid(), CreatedAt = DateTime.Now, Name = l }); } context.SaveChanges(); #endregion }
public static void Seed(WFPICTContext context) { // Permissions foreach (var permission in SecurityConstants.ClaimsAll) { context.Claims.Add(new AspNetClaims() { Id = Guid.NewGuid(), CreatedAt = DateTime.Now, ClaimType = permission.Contains(PermissionType.Order.ToLower()) ? PermissionType.Order : PermissionType.Permission, ClaimValue = permission }); } context.SaveChanges(); // Roles var RoleManager = new RoleManager <WFPRole>(new RoleStore <WFPRole>(context)); if (!RoleManager.RoleExists(SecurityConstants.RoleAdmin)) { RoleManager.Create(new WFPRole(SecurityConstants.RoleAdmin, false, false, "Admin Role")); AddClaims(context, RoleManager, SecurityConstants.RoleAdmin, SecurityConstants.ClaimsAdmin); } if (!RoleManager.RoleExists(SecurityConstants.RoleEmployee)) { RoleManager.Create(new WFPRole(SecurityConstants.RoleEmployee, false, false, "Employee Role")); AddClaims(context, RoleManager, SecurityConstants.RoleEmployee, SecurityConstants.ClaimsAdmin); } if (!RoleManager.RoleExists(SecurityConstants.RolePrivate)) { RoleManager.Create(new WFPRole(SecurityConstants.RolePrivate, false, false, "Private Role")); AddClaims(context, RoleManager, SecurityConstants.RolePrivate, SecurityConstants.ClaimsDefault); } if (!RoleManager.RoleExists(SecurityConstants.RoleDealer)) { RoleManager.Create(new WFPRole(SecurityConstants.RoleDealer, false, false, "Dealer Role")); AddClaims(context, RoleManager, SecurityConstants.RoleDealer, SecurityConstants.ClaimsDefault); } if (!RoleManager.RoleExists(SecurityConstants.RoleManufacturer)) { RoleManager.Create(new WFPRole(SecurityConstants.RoleManufacturer, false, false, "Manufacturer Role")); AddClaims(context, RoleManager, SecurityConstants.RoleManufacturer, SecurityConstants.ClaimsDefault); } var UserManager = new UserManager <WFPUser>(new UserStore <WFPUser>(context)); var alreadyAdminUser = UserManager.FindByName(SecurityConstants.UserAdmin); if (alreadyAdminUser == null) { var adminUser = new WFPUser() { Id = Guid.NewGuid().ToString(), UserName = SecurityConstants.UserAdmin, Email = "*****@*****.**", FirstName = "Admin", LastName = "User", CreatedAt = DateTime.Now }; var result = UserManager.CreateAsync(adminUser, SecurityConstants.UserAdminPassword); if (result.Result == IdentityResult.Success) { var result1 = UserManager.AddToRole(adminUser.Id, SecurityConstants.RoleAdmin); } } var alreadyTestUser = UserManager.FindByName(SecurityConstants.TestEmployeeUser); if (alreadyTestUser == null) { var user = new WFPUser() { Id = Guid.NewGuid().ToString(), UserName = SecurityConstants.TestEmployeeUser, Email = "*****@*****.**", FirstName = "Test", LastName = "User", CreatedAt = DateTime.Now }; var result = UserManager.CreateAsync(user, SecurityConstants.UserAdminPassword); if (result.Result == IdentityResult.Success) { var result1 = UserManager.AddToRole(user.Id, SecurityConstants.RolePrivate); } } }
public void Save() { context.SaveChanges(); }