Exemple #1
0
 public Request(string from, string to, DateTime departDate, int hourFrom = 0, int hourTo = 24)
 {
     From       = from;
     To         = to;
     DepartDate = departDate;
     DepartTime = HourInterval.Get(hourFrom, hourTo);
 }
Exemple #2
0
        public ActionResult Create(HourInterval hourInterval)
        {
            if (hourInterval.Id == 0)
            {
                _context.HourIntervals.Add(hourInterval);
            }
            _context.SaveChanges();

            return(RedirectToAction("Index", "HourIntervals"));
        }
Exemple #3
0
        public ActionResult CreateFormMyJobs(HourInterval hourInterval)
        {
            /*Getting acces to validation data with ModelState property
            if ModelState is not valid
                we return the same view, the view that include the customer form
            else
                we save or update
             */
            if (!ModelState.IsValid)
            {

                var viewModel = new HourIntervalJobs
                {
                    HourInterval = hourInterval,
                    Jobs = _context.Jobs.ToList()
                };
                return View("CreateFormMyJobs",viewModel);
            }

            if (hourInterval.Id == 0)
            {
                hourInterval.ApplicationUserId = User.Identity.GetUserId();
                hourInterval.DateAdded = DateTime.Now;
                hourInterval.TotalTime = Math.Round((hourInterval.TimeEnded - hourInterval.TimeStarted).TotalHours, 2);
                _context.HourIntervals.Add(hourInterval);
            }else
            {
                var hourIntervalInDb = _context.HourIntervals.Single(h => h.Id == hourInterval.Id);

                hourIntervalInDb.Description = hourInterval.Description;
                hourIntervalInDb.TimeStarted = hourInterval.TimeStarted;
                hourIntervalInDb.TimeEnded = hourInterval.TimeEnded;
                hourIntervalInDb.ApplicationUserId = hourInterval.ApplicationUserId;
                hourIntervalInDb.JobId = hourInterval.JobId;
                hourIntervalInDb.DateAdded = hourIntervalInDb.DateAdded;
                hourIntervalInDb.TotalTime = hourInterval.TotalTime;
            }
            _context.SaveChanges();
            return RedirectToAction("Index", "MyJobs");

        }