public void Save(AuthContext context) { if (saveMask == AccountCurrencySaveMask.None) { return; } var model = new AccountCurrencyModel { Id = accountId, CurrencyId = (byte)CurrencyId, Amount = Amount }; if ((saveMask & AccountCurrencySaveMask.Create) != 0) { context.Add(model); } else if ((saveMask & AccountCurrencySaveMask.Amount) != 0) { EntityEntry <AccountCurrencyModel> entity = context.Attach(model); entity.Property(p => p.Amount).IsModified = true; } saveMask = AccountCurrencySaveMask.None; }
public async Task <object> Update(StorePage sp) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var rec = _db.StorePage.Find(sp.Id); if (rec == null) { StorePage newStore = new StorePage { Heading = sp.Heading, Description = sp.Description, PurchaseInfo = sp.PurchaseInfo, PurchaseInfoHeading = sp.PurchaseInfoHeading }; _db.Add(newStore); } else { rec.Heading = sp.Heading; rec.Description = sp.Description; rec.PurchaseInfo = sp.PurchaseInfo; rec.PurchaseInfoHeading = sp.PurchaseInfoHeading; rec.LocationList = sp.LocationList; } await _db.SaveChangesAsync(); return(Ok("200")); }
public ServerResult <User> create(User entity, bool withMsg = true) { ServerResult <User> sr = passCreateGurd(entity); if (!sr.success) { return(sr); } sr = getByUniqueParams(entity, withMsg); if (sr.success) { sr.error.addMessage(HttpError.entityExist, withMsg); sr.fail(); } else { sr.succeed(); sr.result = new User(); sr.result.apiId = entity.apiId; if (sr.result.apiId == null) { sr.result.apiId = Helper.Helper.RandomId(); } sr.result.name = entity.name; sr.result.email = entity.email; sr.result.password = entity.password; sr.error.addInfo(HttpError.getAddIdIntoTable(TabelList.User, sr.result.apiId)); db.Add(sr.result); db.SaveChanges(); } return(sr); }
public async Task <object> Update(CheckeredEyesPage cep) { var rec = _db.CheckeredEyesPages.Find(cep.Id); if (rec == null) { CheckeredEyesPage tempCep = new CheckeredEyesPage { AttentionLowVissionBlockTitle = cep.AttentionLowVissionBlockTitle, AttentionLowVisionBlockContent = cep.AttentionLowVisionBlockContent, AttentionSightedBlockTitle = cep.AttentionSightedBlockTitle, AttentionSightedBlockContent = cep.AttentionSightedBlockContent, SymbolUseBlockTitle = cep.SymbolUseBlockTitle, SymbolUseBlockDescription = cep.SymbolUseBlockDescription, SymbolUseQAList = cep.SymbolUseQAList }; _db.Add(tempCep); } else { rec.AttentionLowVissionBlockTitle = cep.AttentionLowVissionBlockTitle; rec.AttentionLowVisionBlockContent = cep.AttentionLowVisionBlockContent; rec.AttentionSightedBlockTitle = cep.AttentionSightedBlockTitle; rec.AttentionSightedBlockContent = cep.AttentionSightedBlockContent; rec.SymbolUseBlockTitle = cep.SymbolUseBlockTitle; rec.SymbolUseBlockDescription = cep.SymbolUseBlockDescription; rec.SymbolUseQAList = cep.SymbolUseQAList; } await _db.SaveChangesAsync(); return(Ok("200")); }
public async Task <Model.Response.ApplicationUser> InsertAsync(Model.Request.ApplicationUserInsert user, params Enum.Roles[] roles) { Database.ApplicationUser model = mapper.Map <Database.ApplicationUser>(user); try { model.PasswordHash = PasswordHasher.HashPassword(model, user.Password); context.Users.Add(model); await context.SaveChangesAsync(); foreach (var item in roles) { Database.ApplicationRole role = await context.Roles.FirstOrDefaultAsync(x => x.Name == item.ToString()); context.Add(new Database.ApplicationUserRole() { RoleId = role.Id, UserId = model.Id }); await context.SaveChangesAsync(); } // TODO: Dodati log operaciju } catch (Exception e) { // TODO Dodati log operaciju throw e; } return(mapper.Map <Model.Response.ApplicationUser>(model)); }
public void Save(AuthContext context) { if (saveMask == SaveMask.None) { return; } var model = new AccountEntitlementModel { Id = accountId, EntitlementId = (byte)Type, Amount = amount }; if ((saveMask & SaveMask.Create) != 0) { context.Add(model); } else { EntityEntry <AccountEntitlementModel> entity = context.Attach(model); entity.Property(p => p.Amount).IsModified = true; } saveMask = SaveMask.None; }
public async Task <object> Update(AboutPage ap) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var rec = _db.AboutPage.Find(ap.Id); if (rec == null) { AboutPage tempAbout = new AboutPage { AboutBlockHeading = ap.AboutBlockHeading, AboutBlockContent = ap.AboutBlockContent, AchnowledgementsBlockTitle = ap.AchnowledgementsBlockTitle, AchnowledgementsBlockDescription = ap.AchnowledgementsBlockDescription, AchnowledgementsBlockList = ap.AchnowledgementsBlockList, FAQBlockQA = ap.FAQBlockQA }; _db.Add(tempAbout); } else { rec.AboutBlockHeading = ap.AboutBlockHeading; rec.AboutBlockContent = ap.AboutBlockContent; rec.AchnowledgementsBlockTitle = ap.AchnowledgementsBlockTitle; rec.AchnowledgementsBlockDescription = ap.AchnowledgementsBlockDescription; rec.AchnowledgementsBlockList = ap.AchnowledgementsBlockList; rec.FAQBlockQA = ap.FAQBlockQA; } await _db.SaveChangesAsync(); return(Ok("200")); }
public IActionResult Checkout() { // orderD.Quantity = 0; List <String> prodList = new List <String>(); Order order = new Order(); //OrderDetails orderD = new OrderDetails(); var store = SessionHelper.GetObjectFromJson <List <Store> >(HttpContext.Session, "store"); var cart = SessionHelper.GetObjectFromJson <List <ShoppingCart> >(HttpContext.Session, "cart"); Store lastStore = store.Last(); var inventory = HelperMethods.ReturnInventoryById(_context, lastStore.StoreId); int numprod = inventory.Count(); var user = FindUser().Result; order.ApplicationUser = user; order.OrderTime = DateTime.Now; try { order.totalamount = cart.Sum(item => item.Product.Price * item.Quantity); } catch (ArgumentNullException ex) { return(Redirect(Request.Headers["Referer"].ToString())); } order.StoreId = lastStore.StoreId; _context.Order.Add(order); foreach (var item in cart) { OrderDetails orderD = new OrderDetails(); // prodList.Add(item.Product.Name); var product = HelperMethods.ReturnProductById(_context, item.Product.ProductId); orderD.Product = product.Last(); orderD.Quantity = item.Quantity; orderD.productNames = prodList.ToArray(); orderD.Order = order; _context.Add(orderD); _context.SaveChanges(); for (int p = 0; p < numprod; p++) { if (item.Product.ProductId == inventory[p].Product.ProductId) { inventory[p].Quantity = inventory[p].Quantity - item.Quantity; _context.SaveChanges(); } } } //orderD.productNames = prodList.ToArray(); //order.Details = orderD; // _context.OrderDetails.Add(orderD); return(RedirectToAction("OrdersMade")); }
public async Task <IActionResult> Create([Bind("Id,Email,Password,Username,Name,Surname")] Account account) { if (ModelState.IsValid) { _context.Add(account); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(account)); }
public void Save(AuthContext context) { if (!isDirty) { return; } var model = new AccountGenericUnlockModel { Id = accountId, Entry = Entry.Id }; context.Add(model); isDirty = false; }
public async Task <bool> RegistrationUser(string email, string password) { var user = await context.Users.SingleOrDefaultAsync(x => x.Email == email && x.Password == password); if (user == null) { User newUser = new User() { Email = email, Password = password }; context.Add(newUser); await context.SaveChangesAsync(); return(true); } return(false); }
public async Task <object> Update(ContactInfo ci) { var rec = _db.ContactInfo.FirstOrDefault(); string message; if (rec == null) { ContactInfo tempCI = new ContactInfo { Id = ci.Id, StreetName = ci.StreetName, City = ci.City, Province = ci.Province, Country = ci.Country, PostalCode = ci.PostalCode, LocalNumber = ci.LocalNumber, TollFreeNumber = ci.TollFreeNumber, Email = ci.Email, FooterMessage = ci.FooterMessage, HeaderHeading = ci.HeaderHeading, HeaderSubHeading = ci.HeaderSubHeading }; _db.Add(tempCI); message = "Added New Rec"; } else { rec.StreetName = ci.StreetName; rec.Province = ci.Province; rec.City = ci.City; rec.Country = ci.Country; rec.LocalNumber = ci.LocalNumber; rec.TollFreeNumber = ci.TollFreeNumber; rec.Email = ci.Email; rec.FooterMessage = ci.FooterMessage; rec.HeaderHeading = ci.HeaderHeading; rec.HeaderSubHeading = ci.HeaderSubHeading; message = "Updated record"; } await _db.SaveChangesAsync(); return(Ok(message)); }
public async Task <object> Update(HomePage hp) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var rec = _db.HomePage.Find(hp.Id); if (rec == null) { HomePage home = new HomePage { WelcomeBlockHeading = hp.WelcomeBlockHeading, WelcomeBlockContent = hp.WelcomeBlockContent, WelcomeBlockSubHeading = hp.WelcomeBlockSubHeading, MissionStatementBlockHeading = hp.MissionStatementBlockHeading, MissionStatementBlockContent = hp.MissionStatementBlockContent, MissionStatementBlockSubHeading = hp.MissionStatementBlockSubHeading, EmbededVideoUrl = hp.EmbededVideoUrl, VideoDescription = hp.VideoDescription, VideoTitle = hp.VideoTitle }; _db.Add(home); } else { rec.WelcomeBlockHeading = hp.WelcomeBlockHeading; rec.WelcomeBlockContent = hp.WelcomeBlockContent; rec.WelcomeBlockSubHeading = hp.WelcomeBlockSubHeading; rec.MissionStatementBlockHeading = hp.MissionStatementBlockHeading; rec.MissionStatementBlockContent = hp.MissionStatementBlockContent; rec.MissionStatementBlockSubHeading = hp.MissionStatementBlockSubHeading; rec.EmbededVideoUrl = hp.EmbededVideoUrl; rec.VideoDescription = hp.VideoDescription; rec.VideoTitle = hp.VideoTitle; } await _db.SaveChangesAsync(); return(Ok("200")); }
public void Save(AuthContext context) { if (saveMask == CostumeUnlockSaveMask.None) { return; } var model = new AccountCostumeUnlockModel { Id = accountId, ItemId = ItemId }; if ((saveMask & CostumeUnlockSaveMask.Create) != 0) { context.Add(model); } else { context.Entry(model).State = EntityState.Deleted; } saveMask = CostumeUnlockSaveMask.None; }
public void Save(AuthContext context) { if (saveMask == SaveMask.None) { return; } var model = new AccountRoleModel { Id = Id, RoleId = (uint)Role.Role }; if ((saveMask & SaveMask.Create) != 0) { context.Add(model); } else { context.Remove(model); } saveMask = SaveMask.None; }
public void Save(AuthContext context) { if (saveMask == SaveMask.None) { return; } var model = new AccountPermissionModel { Id = Id, PermissionId = (uint)Permission.Permission }; if ((saveMask & SaveMask.Create) != 0) { context.Add(model); } else { context.Remove(model); } saveMask = SaveMask.None; }
public void Save(AuthContext context) { if ((saveMask & BindingSaveMask.Create) != 0) { var model = new AccountKeybinding { Id = (uint)Owner, InputActionId = InputActionId, DeviceEnum00 = DeviceEnum00, DeviceEnum01 = DeviceEnum01, DeviceEnum02 = DeviceEnum02, Code00 = Code00, Code01 = Code01, Code02 = Code02, MetaKeys00 = MetaKeys00, MetaKeys01 = MetaKeys01, MetaKeys02 = MetaKeys02, EventTypeEnum00 = EventTypeEnum00, EventTypeEnum01 = EventTypeEnum01, EventTypeEnum02 = EventTypeEnum02 }; context.Add(model); } else { var model = new AccountKeybinding { Id = (uint)Owner, InputActionId = InputActionId }; if ((saveMask & BindingSaveMask.Delete) != 0) { context.Entry(model).State = EntityState.Deleted; } else { EntityEntry <AccountKeybinding> entity = context.Attach(model); if ((saveMask & BindingSaveMask.DeviceEnum00) != 0) { model.DeviceEnum00 = DeviceEnum00; entity.Property(p => p.DeviceEnum00).IsModified = true; } if ((saveMask & BindingSaveMask.DeviceEnum01) != 0) { model.DeviceEnum01 = DeviceEnum01; entity.Property(p => p.DeviceEnum01).IsModified = true; } if ((saveMask & BindingSaveMask.DeviceEnum02) != 0) { model.DeviceEnum02 = DeviceEnum02; entity.Property(p => p.DeviceEnum02).IsModified = true; } if ((saveMask & BindingSaveMask.Code00) != 0) { model.Code00 = Code00; entity.Property(p => p.Code00).IsModified = true; } if ((saveMask & BindingSaveMask.Code01) != 0) { model.Code01 = Code01; entity.Property(p => p.Code01).IsModified = true; } if ((saveMask & BindingSaveMask.Code02) != 0) { model.Code02 = Code02; entity.Property(p => p.Code02).IsModified = true; } if ((saveMask & BindingSaveMask.MetaKeys00) != 0) { model.MetaKeys00 = MetaKeys00; entity.Property(p => p.MetaKeys00).IsModified = true; } if ((saveMask & BindingSaveMask.MetaKeys01) != 0) { model.MetaKeys01 = MetaKeys01; entity.Property(p => p.MetaKeys01).IsModified = true; } if ((saveMask & BindingSaveMask.MetaKeys02) != 0) { model.MetaKeys02 = MetaKeys02; entity.Property(p => p.MetaKeys02).IsModified = true; } if ((saveMask & BindingSaveMask.EventTypeEnum00) != 0) { model.EventTypeEnum00 = EventTypeEnum00; entity.Property(p => p.EventTypeEnum00).IsModified = true; } if ((saveMask & BindingSaveMask.EventTypeEnum01) != 0) { model.EventTypeEnum01 = EventTypeEnum01; entity.Property(p => p.EventTypeEnum01).IsModified = true; } if ((saveMask & BindingSaveMask.EventTypeEnum02) != 0) { model.EventTypeEnum02 = EventTypeEnum02; entity.Property(p => p.EventTypeEnum02).IsModified = true; } saveMask = BindingSaveMask.None; } } }