Ejemplo n.º 1
0
        public async Task <IActionResult> NewCategory([Bind("CatId,CatType,CatBed,CatDescription,CatPrice")] TCategory tCat)
        {
            if (HttpContext.Session.GetString("UType") != "A")
            {
                TempData["Error"] = "Insufficient login permission";
                return(RedirectToAction("Index", "Login"));
            }
            SetDashboard(2);
            if (ModelState.IsValid)
            {
                try
                {
                    _context.Add(tCat);
                    await _context.SaveChangesAsync();

                    TempData["Message"] = "Category registered.";
                    return(RedirectToAction(nameof(ViewCategory)));
                }
                catch (Exception)
                {
                    TempData["Error"] = "Unable to register this category. Please try agian";
                    return(View(tCat));
                }
            }

            TempData["Error"] = "Unable to register this category. Please try agian";
            return(View(tCat));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("UserName,UserPass,UserEmail,UserAddress,UserTp")] TUser tUser)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    tUser.UserStatus = 1;
                    tUser.ShaEnc();
                    _context.Add(tUser);
                    await _context.SaveChangesAsync();

                    TempData["Message"] = "User registered.";
                    return(RedirectToAction(nameof(Index)));
                }
                catch (Exception ex)
                {
                    if (ex.InnerException.ToString().Contains("Violation of UNIQUE KEY constraint"))
                    {
                        ViewBag.Error = "This email is already used. Please use another email address";
                    }
                    else
                    {
                        ViewBag.Error = "Unable to register this user. Please try agian";
                    }
                    return(View(tUser));
                }
            }

            ViewBag.Error = "Unable to register this user. Please try agian";
            return(View(tUser));
        }
Ejemplo n.º 3
0
        //Confirm reservation
        public async System.Threading.Tasks.Task <IActionResult> MakeReservation()
        {
            if (HttpContext.Session.GetInt32("pending") != 1)
            {
                return(RedirectToAction(nameof(Index)));
            }

            var dateFrom = DateTime.Parse(HttpContext.Session.GetString("resFrom"));
            var dateTo   = DateTime.Parse(HttpContext.Session.GetString("resTo"));
            var uid      = HttpContext.Session.GetInt32("UID");

            var tRes = new TReservation {
                ResFrom = dateFrom, ResTo = dateTo, UserId = uid
            };

            _context.Add(tRes);
            if (await _context.SaveChangesAsync() > 0)
            {
                int resId    = _context.TReservations.Max(x => x.ResId);
                var listRoom = JsonConvert.DeserializeObject <List <TRoom> >(HttpContext.Session.GetString("rooms"));
                var resRoom  = new List <TReservationRoom>();

                foreach (var item in listRoom)
                {
                    var temp = new TReservationRoom {
                        ResId = resId, RoomId = decimal.ToInt16(item.RoomId)
                    };
                    resRoom.Add(temp);
                }

                _context.TReservationRooms.AddRange(resRoom);
                if (await _context.SaveChangesAsync() > 0)
                {
                    HttpContext.Session.SetInt32("pending", 0);
                    HttpContext.Session.SetString("rooms", "");
                    return(RedirectToAction(nameof(Complete)));
                }
            }

            TempData["Error"] = "Unable to create the reservation. Please try again";
            return(RedirectToAction(nameof(Reservation)));
        }