Exemplo n.º 1
0
        public ActionResult StartFreeze(FreezeDownViewModel fdvm)
        {
            try
            {
                User user = new User()
                {
                    UserName = fdvm.UserName,
                    Password = fdvm.Password
                };

                int UserID = _repo.IsValidUser(user);
                if (UserID == 0)
                {
                    Response.StatusCode = (int)HttpStatusCode.BadRequest;
                    return(Json("Invalid UserName or Password", MediaTypeNames.Text.Plain));
                }


                bool IsCartValid = _repo.IsCartValid(fdvm.LineNumberStart, fdvm.CartNumberStart.GetValueOrDefault());
                if (IsCartValid == false)
                {
                    Response.StatusCode = (int)HttpStatusCode.BadRequest;
                    return(Json("Please Select a Valid Cart", MediaTypeNames.Text.Plain));
                }

                bool IsCartInUse = _repo.IsCartInUse(fdvm.LineNumberStart, fdvm.CartNumberStart.GetValueOrDefault());
                if (IsCartInUse == true)
                {
                    Response.StatusCode = (int)HttpStatusCode.BadRequest;
                    return(Json("Cart Is In Use - Please Select Another", MediaTypeNames.Text.Plain));
                }


                string LocationCode = fdvm.LocationCode;
                int    LocationID   = _repo.GetLocationID(LocationCode);


                string LineNumber = fdvm.LineNumberStart;
                int    CartNumber = fdvm.CartNumberStart.GetValueOrDefault();
                int    CartID     = _repo.GetCartID(LineNumber, CartNumber);

                var docking = new Docking();
                docking.LocationID = LocationID;
                docking.CartID     = CartID;
                docking.StartTime  = DateTime.Now;
                //docking.EndTime = docking.StartTime.GetValueOrDefault().AddHours(5);
                //docking.EndTime = docking.StartTime.GetValueOrDefault().AddMinutes(1);
                docking.EndTime    = docking.StartTime.GetValueOrDefault().AddSeconds(90);
                docking.IsActive   = true;
                docking.InsertDate = DateTime.Now.ConvertToEST();
                docking.InsertBy   = UserID;
                //docking.LastUpdate = DateTime.Now.ConvertToEST();
                //docking.LastUpdateBy = UserID;

                bool rslt = false;


                if (ModelState.IsValid)
                {
                    rslt = _repo.CreateDocking(docking);
                }

                if (rslt == true)
                {
                    return(Json(Url.Action("Index", "Timer")));
                }
                else
                {
                    Response.StatusCode = (int)HttpStatusCode.BadRequest;
                    return(Json("Docking Record Creation In Database Failed", MediaTypeNames.Text.Plain));
                }
            }
            catch (Exception ex)
            {
                TempData["FreezeDownError"] = ex;
                return(RedirectToAction("ShowError", "Error"));
            }
        }