public ActionResult UpdateInline(OrderTypeModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    bool validate = true;
                    if (model.DateFrom > model.DateTo)
                    {
                        validate = false;
                        ViewData["EditError"] = "From Date cannot be less than To Date.";
                    }

                    model.CompanyId = AuthenticationHelper.CompanyId.Value;
                    
                    if (validate)
                        OrderTypeHelper.Save(model);
                }
                catch (Exception e)
                {
                    ViewData["EditError"] = e.Message;
                }
            }
            else
                ViewData["EditError"] = "Please, correct all errors.";
            return PartialView("_List", OrderTypeHelper.GetOrderTypes());
        }
        private static OrderType getEntityByModel(OrderTypeModel model)
        {
            if (model == null) return null;

            OrderType entity = new OrderType();

            if (model.Id == 0)
            {
                entity.CreateBy = AuthenticationHelper.UserId;
                entity.CreateDate = DateTime.Now;
                entity.CompanyId = AuthenticationHelper.CompanyId.Value;
            }
            else
            {
                entity.CreateBy = model.CreateBy;
                entity.CreateDate = model.CreateDate;
                entity.CompanyId = model.CompanyId;
            }

            entity.DateFrom = model.DateFrom;
            entity.DateTo = model.DateTo;
            entity.Id = model.Id;
            entity.OrderTypeName = model.OrderTypeName;
            entity.SOBId = SessionHelper.SOBId;
            entity.UpdateBy = AuthenticationHelper.UserId;
            entity.UpdateDate = DateTime.Now;

            return entity;
        }
        public ActionResult DeleteInline(OrderTypeModel model)
        {
            try
            {
                model.CompanyId = AuthenticationHelper.CompanyId.Value;
                OrderTypeHelper.Delete(model.Id.ToString());
                return PartialView("_List", OrderTypeHelper.GetOrderTypes());
            }
            catch (Exception e)
            {
                ViewData["EditError"] = e.Message;
            }

            return PartialView("_List", OrderTypeHelper.GetOrderTypes());
        }
 public static string Save(OrderTypeModel model)
 {
     if (model.Id > 0)
     {
         OrderType savedOrder = service.GetSingle(model.Id.ToString(), AuthenticationHelper.CompanyId.Value);
         if(savedOrder != null)
         {
             model.CreateDate = savedOrder.CreateDate;
             model.CreateBy = savedOrder.CreateBy;
             model.UpdateDate = savedOrder.UpdateDate;
             model.UpdateBy = savedOrder.UpdateBy;
         }
         return service.Update(getEntityByModel(model));
     }
     else
         return service.Insert(getEntityByModel(model));
 }