public ActionResult Edit([Bind(Include = "Sch_Id,Departure_Location,Arrival_Location,Dept_DateTime,Arrvl_DateTime,Ship_Id")] Schedule_tbl schedule_tbl)
 {
     if (ModelState.IsValid)
     {
         if (checkSchedule(schedule_tbl) == true)
         {
             Schedule_tbl targetSchedule = db.Schedule_tbl.Find(schedule_tbl.Sch_Id);
             targetSchedule.Arrival_Location    = schedule_tbl.Arrival_Location;
             targetSchedule.Arrvl_DateTime      = schedule_tbl.Arrvl_DateTime;
             targetSchedule.Departure_Location  = schedule_tbl.Departure_Location;
             targetSchedule.Dept_DateTime       = schedule_tbl.Dept_DateTime;
             targetSchedule.Ship_Id             = schedule_tbl.Ship_Id;
             targetSchedule.Available_Container = db.Ship_tbl.Find(targetSchedule.Ship_Id).Container_Limit;
             db.Entry(targetSchedule).State     = EntityState.Modified;
             db.SaveChanges();
             TempData["message"] = "Schedule has been edited!";
             return(RedirectToAction("ScheduleManagement"));
         }
         else
         {
             ViewBag.PortLocation = getLocation();
             ViewBag.ShipList     = getShips();
             return(View());
         }
     }
     return(View(schedule_tbl));
 }
        public Boolean checkSchedule(Schedule_tbl sch_input)
        {
            Boolean check   = true;
            var     schList = db.Schedule_tbl.Where(a => a.Ship_Id == sch_input.Ship_Id && a.Sch_Id != sch_input.Sch_Id);

            if (sch_input.Departure_Location == sch_input.Arrival_Location)
            {
                TempData["message"] = "Departure and Arrival Location must be different!";
                check = false;
            }
            else if (sch_input.Dept_DateTime > sch_input.Arrvl_DateTime)
            {
                TempData["message"] = "Departure date must be earier than arrival date!";
                check = false;
            }
            else if (sch_input.Dept_DateTime < DateTime.Now)
            {
                TempData["message"] = "Please select future departure date!";
                check = false;
            }
            if (schList != null)
            {
                foreach (var schedule in schList)
                {
                    if ((sch_input.Dept_DateTime >= schedule.Dept_DateTime && sch_input.Dept_DateTime <= schedule.Arrvl_DateTime) ||
                        (sch_input.Arrvl_DateTime >= schedule.Dept_DateTime && sch_input.Arrvl_DateTime <= schedule.Arrvl_DateTime))
                    {
                        TempData["message"] = "The vessel is reserved by other schdule on the selected period!";
                        check = false;
                    }
                }
            }

            return(check);
        }
Example #3
0
        public ActionResult GetScheduleInfo(string scheduleId)
        {
            int  n;
            bool result = Int32.TryParse(scheduleId, out n);

            if (result == true)
            {
                int           schId    = Convert.ToInt32(scheduleId);
                Schedule_tbl  schTable = db.Schedule_tbl.Find(schId);
                List <string> schInfo  = new List <string>();
                schInfo.Add(schTable.Departure_Location);
                schInfo.Add(schTable.Arrival_Location);
                schInfo.Add(schTable.Dept_DateTime.ToString());
                schInfo.Add(schTable.Arrvl_DateTime.ToString());
                schInfo.Add(schTable.Ship_Name);
                schInfo.Add(schTable.Available_Container.ToString());
                return(Json(schInfo, JsonRequestBehavior.AllowGet));
            }
            else
            {
                List <string> schInfo = new List <string>();
                schInfo.Add("");
                schInfo.Add("");
                schInfo.Add("");
                schInfo.Add("");
                schInfo.Add("");
                schInfo.Add("");
                return(Json(schInfo, JsonRequestBehavior.AllowGet));
            }
        }
Example #4
0
        public static ScheduleDTO NewSchedule(ScheduleDTO s)
        {
            Schedule_tbl sdal = ScheduleDTO.ToDAL(s);
            Schedule_tbl stbl = DAL.ScheduleDAL.NewSchedule(sdal);

            return(new ScheduleDTO(stbl));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            Schedule_tbl schedule_tbl = db.Schedule_tbl.Find(id);

            db.Schedule_tbl.Remove(schedule_tbl);
            db.SaveChanges();
            TempData["message"] = "Schedule Deleted!";
            return(RedirectToAction("ScheduleManagement"));
        }
        // GET: Schedule/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Schedule_tbl schedule_tbl = db.Schedule_tbl.Find(id);

            if (schedule_tbl == null)
            {
                return(HttpNotFound());
            }
            return(View(schedule_tbl));
        }
        // GET: Schedule/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Schedule_tbl schedule_tbl = db.Schedule_tbl.Find(id);

            if (db.Booking_tbl.Where(a => a.Sch_Id == schedule_tbl.Sch_Id).Count() > 0)
            {
                TempData["message"] = "This schedule cannot be delete, it has been booked!";
                return(RedirectToAction("ScheduleManagement"));
            }
            if (schedule_tbl == null)
            {
                return(HttpNotFound());
            }
            return(View(schedule_tbl));
        }
        public ActionResult Create([Bind(Include = "Sch_Id,Departure_Location,Arrival_Location,Dept_DateTime,Arrvl_DateTime,Ship_Id,Available_Container")] Schedule_tbl schedule_tbl)
        {
            if (ModelState.IsValid)
            {
                if (checkSchedule(schedule_tbl) == true)
                {
                    schedule_tbl.Available_Container = db.Ship_tbl.Find(schedule_tbl.Ship_Id).Container_Limit;
                    db.Schedule_tbl.Add(schedule_tbl);
                    db.SaveChanges();
                    TempData["message"] = "New Schedule Registered!";
                    return(RedirectToAction("ScheduleManagement", "Schedule"));
                }
                else
                {
                    ViewBag.PortLocation = getLocation();
                    ViewBag.ShipList     = getShips();
                    return(View());
                }
            }

            return(View(schedule_tbl));
        }
Example #9
0
        public ActionResult Create(List <BookingItem_tbl> items, string schId)
        {
            int  n;
            bool result = int.TryParse(schId, out n);

            if (result == false)
            {
                TempData["message"] = "Please Select a schedule";

                return(Json(Url.Action("Create", "Booking")));
            }
            else if (items == null)
            {
                TempData["message"] = "Please add an item";
                return(Json(Url.Action("Create", "Booking")));
            }
            else if (items != null)
            {
                bool checkItem = true;
                //string message = null;
                int itemCount = 0;
                foreach (var item in items.ToList())
                {
                    if (item.Itm_Id.ToString() == "" || item.Container_No.ToString() == "")
                    {
                        checkItem = false;
                        break;
                    }
                }

                if (checkItem == true)
                {
                    int          scheduleId     = Convert.ToInt32(schId);
                    Schedule_tbl targetSchedule = db.Schedule_tbl.Find(scheduleId);
                    foreach (var item in items)
                    {
                        itemCount = itemCount + item.Container_No;
                    }
                    if (targetSchedule.Available_Container >= itemCount)
                    {
                        Booking_tbl newBooking = new Booking_tbl();
                        newBooking.Bk_Date  = DateTime.Now;
                        newBooking.Agent_Id = Convert.ToInt32(Session["userId"].ToString());
                        newBooking.Sch_Id   = scheduleId;
                        db.Booking_tbl.Add(newBooking);
                        db.SaveChanges();

                        foreach (var item in items.ToList())
                        {
                            BookingItem_tbl newBI = new BookingItem_tbl();
                            newBI.Itm_Id       = item.Itm_Id;
                            newBI.Container_No = item.Container_No;
                            newBI.Bk_Id        = newBooking.Bk_Id;
                            db.BookingItem_tbl.Add(newBI);
                            db.SaveChanges();
                        }


                        targetSchedule.Available_Container = targetSchedule.Available_Container - itemCount;
                        db.Entry(targetSchedule).State     = EntityState.Modified;
                        db.SaveChanges();

                        //message = "New Booking Created!";
                        //return Json(message);
                        TempData["message"] = "New Booking Created!";
                        return(Json(Url.Action("ViewBooking", "Booking")));
                    }
                    else
                    {
                        //message = "Not enought container for the items!";
                        //return Json(message);
                        TempData["message"] = "Not enought container for the items!";
                        return(Json(Url.Action("Create", "Booking")));
                    }
                }
                else
                {
                    //message = "Please make sure all items are added properly!";
                    //return Json(message);
                    TempData["message"] = "Please make sure all items are added properly!";
                    return(Json(Url.Action("Create", "Booking")));
                }
            }

            return(Json(Url.Action("Create", "Booking")));
        }