public async Task <IActionResult> OnPostAsync() { ViewData["Cities"] = new SelectList(_context.Cities.OrderBy(a => a.Name), "Id", "Name"); if (!ModelState.IsValid) { return(Page()); } _context.Attach(Shop).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ShopExists(Shop.Id)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./IndexShop")); }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(City).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CityExists(City.Id)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Service = await _context.Service.FindAsync(id); if (Service != null) { var Agents = _context.Agent.Where(a => a.ShopId == Service.ShopId).ToList(); foreach (var item in Agents) { if (item.SevicesList.Contains(Service.Id + ":")) { item.SevicesList = item.SevicesList.Replace(Service.Id + ":", ""); _context.Attach(item).State = EntityState.Modified; } } _context.Service.Remove(Service); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } int v = await _context.Shop.Where(s => s.E_mail == _userManager.GetUserName(User)).Select(s => s.Id).FirstOrDefaultAsync(); Service.ShopId = v; _context.Attach(Service).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ServiceExists(Service.Id)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } if (!ModelState.IsValid) { return(Page()); } var shop = await _context.Shop.FindAsync(id); if (await TryUpdateModelAsync <Shop>( shop, "shop", s => s.PhoneNumber, s => s.HolidayEndDate)) { await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } return(Page()); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } City.Name = City.Name.ToUpper(); _context.Cities.Add(City); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync(int?id, string type) { if (!ModelState.IsValid) { return(Page()); } if (id == null || string.IsNullOrEmpty(type)) { return(NotFound()); } if (!VerifyFile()) { ModelState.AddModelError("File", "fichier Invalid"); return(Page()); } using (var memoryStream = new MemoryStream()) { await ImageUpload.FormFile.CopyToAsync(memoryStream); // Upload the file if less than 512 KB if (memoryStream.Length < 524288) { if (type == "shop") { var shop = await _context.Shop.FindAsync(id); shop.Image = memoryStream.ToArray(); _context.Attach(shop).State = EntityState.Modified; } try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { } } else { ModelState.AddModelError("File", "The file is too large. must be less than 512 kb"); return(Page()); } } return(Redirect("/Panel/Manager/Details")); }
public async Task <IActionResult> OnPostCreateAsync(int?pageIndex) { if (ModelState.IsValid) { if (!CityExists(CreateCity.Name.ToUpper())) { CreateCity.Name = CreateCity.Name.ToUpper(); _context.Cities.Add(CreateCity); await _context.SaveChangesAsync(); } } return(Redirect("/Panel/Cities/Index")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } int v = await _context.Shop.Where(s => s.E_mail == _userManager.GetUserName(User)).Select(s => s.Id).FirstOrDefaultAsync(); Service.ShopId = v; _context.Service.Add(Service); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Appointment = await _context.Appointment.FindAsync(id); if (Appointment != null) { _context.Appointment.Remove(Appointment); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } City = await _context.Cities.FindAsync(id); if (City != null) { _context.Cities.Remove(City); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } var user = new ComaCuraswebUser { UserName = Shop.E_mail, Email = Shop.E_mail, FullName = Shop.Name, DOB = DateTime.Now.AddYears(-20), EmailConfirmed = true }; var password = "******"; // to change afterwards var userExists = await _userManager.FindByEmailAsync(user.Email); if (userExists != null) { return(RedirectToPage(new { msg = "Email Already Exits" })); } IdentityResult IR = await _userManager.CreateAsync(user, password); if (IR.Succeeded) { var u = await _userManager.FindByEmailAsync(user.Email); IR = await _userManager.AddToRoleAsync(u, "manager"); if (!IR.Succeeded) { return(RedirectToPage(new { msg = "registration Failed" })); } _context.Shop.Add(Shop); await _context.SaveChangesAsync(); Create_schedule(Shop.Id); return(RedirectToPage("/Admin/IndexShop", new { msg = "registration success" })); } return(RedirectToPage(new { msg = "registration failed" })); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Shop = await _context.Shop.FindAsync(id); if (Shop != null) { _context.Shop.Remove(Shop); await _context.SaveChangesAsync(); await _userManager.DeleteAsync(await _userManager.FindByEmailAsync(Shop.E_mail)); } return(RedirectToPage("./IndexShop")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } if (!ModelState.IsValid) { return(Page()); } var agent = await _context.Agent.FindAsync(id); if (agent == null) { return(NotFound()); } agent.Name = Agent.Name; agent.HolidayEndDate = Agent.HolidayEndDate; _context.Attach(agent).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AgentExists(Agent.Id)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Shop = await _context.Shop.FirstOrDefaultAsync(s => s.Id == id); Services = await _context.Service.Where(s => s.ShopId == id).AsNoTracking().ToListAsync(); Agents = await _context.Agent.Where(s => s.ShopId == id).AsNoTracking().ToListAsync(); Schedule = await _context.Schedule.Where(s => s.ShopId == id).AsNoTracking().ToListAsync(); SelectServicesNames = new SelectList(Services, nameof(Service.Id), nameof(Service.Name)); Appointments = await _context.Appointment .Include(a => a.Service) .Where(a => string.Equals(a.UserMail, _userManager.GetUserName(User))) .Where(a => a.Date.Date >= DateTime.Now.Date) .Where(a => a.ShopId == id) .AsNoTracking() .ToListAsync(); if (Shop == null) { return(NotFound()); } if (!ModelState.IsValid) { return(Page()); } Appointment.UserMail = _userManager.GetUserName(User); Appointment.ShopId = (int)id; _context.Appointment.Add(Appointment); await _context.SaveChangesAsync(); return(RedirectToPage("./Details", new { id = Appointment.ShopId, msg = "Registration success" })); }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync(int?id) { if (!ModelState.IsValid) { return(Page()); } var schedule = await _context.Schedule.FindAsync(id); if (await TryUpdateModelAsync( schedule, "schedule", s => s.Start, s => s.End, s => s.Pstart, s => s.Pend)) { await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } return(RedirectToPage("./Index")); }