private PurchasingPeriod getEntityByModel(PurchasingPeriodModel model)
        {
            if (model == null)
                return null;

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

            entity.CalendarId = model.CalendarId;
            entity.Id = model.Id;
            entity.SOBId = model.SOBId;
            entity.Status = model.Status;
            entity.UpdateBy = AuthenticationHelper.UserId;
            entity.UpdateDate = DateTime.Now;
            return entity;
        }
 private string Save(PurchasingPeriodModel model)
 {
     if (model.Id > 0)
     {
         return service.Update(getEntityByModel(model));
     }
     else
     {
         return service.Insert(getEntityByModel(model));
     }
 }
 public ActionResult DeleteInline(PurchasingPeriodModel model)
 {
     if (ModelState.IsValid)
     {
         try
         {
             model.CompanyId = AuthenticationHelper.CompanyId.Value;
             service.Delete(model.Id.ToString(), model.CompanyId);
             return PartialView("_List", service.GetAll(AuthenticationHelper.CompanyId.Value, SessionHelper.SOBId)
                 .Select(x => new PurchasingPeriodModel(x)).ToList());
         }
         catch (Exception e)
         {
             ViewData["EditError"] = e.Message;
         }
     }
     else
         ViewData["EditError"] = "Please, correct all errors.";
     return PartialView("_List", service.GetAll(AuthenticationHelper.CompanyId.Value, SessionHelper.SOBId)
         .Select(x => new PurchasingPeriodModel(x)).ToList());
 }