コード例 #1
0
        public async Task <IActionResult> OnPostAsync()
        {
            Day.OpenTime = (String)Request.Form["OpenTime"];

            Day.CloseTime = (String)Request.Form["CloseTime"];

            _context.Attach(Day).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DayExists(Day.id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(RedirectToPage(new { day = GetDayValue(Day) }));
        }
コード例 #2
0
        public async Task <IActionResult> OnPostPageAsync(int id, Image Img)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            if (Request.Form.Files.ToArray().Length > 0)
            {
                var file = Request.Form.Files.First();
                Img.ImageName = file.FileName;

                MemoryStream ms = new MemoryStream();
                file.CopyTo(ms);
                Img.ImageVal = ms.ToArray();
                ms.Close();
                ms.Dispose();

                Resturaunt.ResturauntPage.Image = Img;
            }

            _context.Attach(ResturauntPage).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ResturauntPageExists(Day.id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./ResturauntPage", new { id = id }));
        }
コード例 #3
0
        public async Task <IActionResult> OnPostAsync()
        {
            int        id = (int)HttpContext.Session.GetInt32("current_resturaunt");
            Resturaunt R  = await _context.Resturaunt.Include(m => m.ResturauntPage).ThenInclude(m => m.Days).FirstOrDefaultAsync(m => m.id == id);

            foreach (var i in R.ResturauntPage.Days)
            {
                _context.Entry(i)
                .Collection(s => s.Deals)
                .Load();
            }

            var file = Request.Form.Files.First();

            using (var reader = file.OpenReadStream())
            {
                TextReader tr = new StreamReader(reader);
                using (var csv = new CsvReader(tr, CultureInfo.InvariantCulture))
                {
                    csv.Configuration.HasHeaderRecord = false;
                    var deals = csv.GetRecords <CSVDeal>();

                    foreach (var d in deals)
                    {
                        Deal deal = new Deal()
                        {
                            ItemName = d.DealName, Desription = d.DealDescription, StartTime = d.StartTime, EndTime = d.EndTime
                        };
                        _context.Deal.Add(deal);
                        if (deal != null)
                        {
                            R.ResturauntPage.Days.Where(n => n.DayName.ToLower() == d.DayOfWeek.ToLower()).FirstOrDefault().Deals.Add(deal);
                        }
                    }

                    _context.Attach(R).State = EntityState.Modified;

                    try
                    {
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                    }
                }
            }



            return(Page());
        }
コード例 #4
0
        public async Task <IActionResult> OnPostAsync()
        {
            _context.Attach(ResturauntPage).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ResturauntExists((int)HttpContext.Session.GetInt32("current_resturaunt")))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage());
        }
コード例 #5
0
        public async Task <IActionResult> OnPostAsync(Image Img)
        {
            if (Request.Form.Files.ToArray().Length > 0)
            {
                var file = Request.Form.Files.First();
                Img.ImageName = file.FileName;

                MemoryStream ms = new MemoryStream();
                file.CopyTo(ms);
                Img.ImageVal = ms.ToArray();
                ms.Close();
                ms.Dispose();

                Resturaunt.ResturauntPage.Image = Img;
            }

            _context.Attach(Resturaunt).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ResturauntExists((int)HttpContext.Session.GetInt32("current_resturaunt")))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage());
        }