Exemplo n.º 1
0
        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"));
        }
Exemplo n.º 2
0
        // 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"));
        }
Exemplo n.º 3
0
        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"));
        }
Exemplo n.º 4
0
        // 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"));
        }
Exemplo n.º 5
0
        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());
        }
Exemplo n.º 6
0
        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"));
        }
Exemplo n.º 7
0
        // 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"));
        }
Exemplo n.º 8
0
        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"));
        }
Exemplo n.º 9
0
        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"));
        }
Exemplo n.º 10
0
        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"));
        }
Exemplo n.º 11
0
        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"));
        }
Exemplo n.º 12
0
        // 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" }));
        }
Exemplo n.º 13
0
        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"));
        }
Exemplo n.º 14
0
        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"));
        }
Exemplo n.º 15
0
        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" }));
        }
Exemplo n.º 16
0
        // 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"));
        }