/* Render */

        public ActionResult Index()
        {
            Account account = base.GetLoginAccount(false);

            if (account == null || !TimeTypeOperations.CanRender(account))
            {
                return(base.ToLoginPage());
            }
            return(View());
        }
 public ActionResult ReadTimeType(int id)
 {
     using (var context = new DataContext())
     {
         try
         {
             Account  account = base.GetLoginAccount();
             TimeType dbm     = TimeTypeOperations.TryRead(account, context, id);
             return(Json(new UITimeType_RU(dbm)));
         }
         catch (Exception e)
         {
             base.HandleException("ReadTimeType", e);
             return(null);
         }
     }
 }
        public ActionResult DeleteTimeType(int id)
        {
            AjaxStatus status = new AjaxStatus();

            using (var context = new DataContext())
            {
                try
                {
                    Account account = base.GetLoginAccount();
                    TimeTypeOperations.TryDelete(account, context, id);
                    context.SaveChanges();
                }
                catch (Exception e)
                {
                    base.HandleException("DeleteTimeType", e);
                    status.SetError(e.Message);
                }
            }
            return(Json(status));
        }
        public ActionResult UpdateTimeType(UITimeType_RU uim)
        {
            AjaxStatus status = new AjaxStatus();

            using (var context = new DataContext())
            {
                try
                {
                    Account  account = base.GetLoginAccount();
                    TimeType dbm     = TimeTypeOperations.TryRead(account, context, uim.id);
                    dbm = uim.UpdateModel(dbm);
                    TimeTypeOperations.TryUpdate(account, context, dbm);
                    context.SaveChanges();
                }
                catch (Exception e)
                {
                    base.HandleException("UpdateTimeType", e);
                    status.SetError(e.Message);
                }
            }
            return(Json(status));
        }
        public ActionResult ListTimeTypes(int draw, int start, int length)
        {
            using (var context = new DataContext())
            {
                try
                {
                    Account account             = base.GetLoginAccount();
                    IQueryable <TimeType> query = TimeTypeOperations.TryList(account, context);

                    // Possibly apply filter
                    var searchstring = Request["search[value]"];
                    if (!String.IsNullOrWhiteSpace(searchstring))
                    {
                        query = query.Where(c => c.name.Contains(searchstring));
                    }
                    int recordsFiltered = query.Count();

                    // Execute query
                    IList <TimeType> dbms = query.OrderBy(c => c.code).Skip(start).Take(length).ToList();
                    int recordsTotal      = context.TimeTypes.Count();

                    // Compose view models
                    IList <UITimeType_List> uims = new List <UITimeType_List>(dbms.Count);
                    foreach (TimeType dbm in dbms)
                    {
                        uims.Add(new UITimeType_List(dbm));
                    }
                    return(Json(new { draw = draw, recordsTotal = recordsTotal, recordsFiltered = recordsFiltered, data = uims }));
                }
                catch (Exception e)
                {
                    base.HandleException("ListTimeTypes", e);
                    return(null);
                }
            }
        }