public virtual System.Web.Mvc.ActionResult Create(Models.Traffic traffic)
        {
            if (traffic.EndTime < traffic.StartTime)
            {
                string errorMessage =
                    "EndTime Cannot be Smaller Than StartTime";

                ModelState.AddModelError(key: string.Empty, errorMessage: errorMessage);
            }

            if (ModelState.IsValid)
            {
                MyDatabaseContext.Traffics.Add(traffic);
                MyDatabaseContext.SaveChanges();
                return(RedirectToAction(MVC.Traffics.Index()));
            }
            /******************************************************************************************/
            var users =
                MyDatabaseContext.Users
                .Where(current => current.IsActive)
                .OrderBy(current => current.Username)
                .ToList()
            ;

            ViewBag.UserId =
                new System.Web.Mvc.SelectList(items: users, dataValueField: nameof(Models.User.Id), dataTextField: nameof(Models.User.Username),
                                              selectedValue: traffic.UserId);
            /******************************************************************************************/
            return(View(model: traffic));
        }
        public override System.Web.Mvc.ActionResult Edit(Models.Traffic traffic)
        {
            var callInfo = new T4MVC_System_Web_Mvc_ActionResult(Area, Name, ActionNames.Edit);

            ModelUnbinderHelpers.AddRouteValues(callInfo.RouteValueDictionary, "traffic", traffic);
            EditOverride(callInfo, traffic);
            return(callInfo);
        }
        public virtual System.Web.Mvc.ActionResult Details(System.Guid?id)
        {
            if (id.HasValue == false)
            {
                return(new System.Web.Mvc
                       .HttpStatusCodeResult(System.Net.HttpStatusCode.BadRequest));
            }

            Models.Traffic foundedItem =
                MyDatabaseContext.Traffics
                .Where(current => current.Id == id.Value)
                .FirstOrDefault();

            if (foundedItem == null)
            {
                return(HttpNotFound());
            }
            return(View(foundedItem));
        }
        public virtual System.Web.Mvc.ActionResult Edit(Models.Traffic traffic)
        {
            var originalItem =
                MyDatabaseContext.Traffics
                .Where(current => current.Id == traffic.Id)
                .FirstOrDefault()
            ;

            if (originalItem == null)
            {
                return(HttpNotFound());
            }

            if (ModelState.IsValid)
            {
                originalItem.Date      = traffic.Date;
                originalItem.UserId    = traffic.UserId;
                originalItem.EndTime   = traffic.EndTime;
                originalItem.Duration  = traffic.Duration;
                originalItem.StartTime = traffic.StartTime;

                MyDatabaseContext.SaveChanges();
                return(RedirectToAction(MVC.Traffics.Index()));
            }

            /******************************************************************************************/
            var users =
                MyDatabaseContext.Users
                .Where(current => current.IsActive)
                .OrderBy(current => current.Username)
                .ToList()
            ;

            ViewBag.UserId =
                new System.Web.Mvc.SelectList(items: users, dataValueField: nameof(Models.User.Id), dataTextField: nameof(Models.User.Username),
                                              selectedValue: traffic.UserId);
            /******************************************************************************************/

            return(View(model: traffic));
        }
 partial void EditOverride(T4MVC_System_Web_Mvc_ActionResult callInfo, Models.Traffic traffic);