Exemple #1
0
 public int?SaveCategories(CategoriesSaveRequest request)
 {
     if (request.Id != null)
     {
         var categories = _categoriesRepository.GetSingleNoneDeleted(x => x.Id == request.Id);
         //update
         if (categories != null)
         {
             categories.Name         = request.Name;
             categories.Description  = request.Description;
             categories.ModifiedDate = Constants.GetDateNow();
             categories.ModifiedBy   = Constants.GetUserId();
             _categoriesRepository.Update(categories);
             _categoriesRepository.Commit();
         }
         if (categories != null)
         {
             return(categories.Id);
         }
     }
     else
     {
         //add new
         var newCat = new Categories
         {
             Name         = request.Name,
             Description  = request.Description,
             CreatedBy    = Constants.GetUserId(),
             ModifiedBy   = Constants.GetUserId(),
             CreatedDate  = Constants.GetDateNow(),
             ModifiedDate = Constants.GetDateNow()
         };
         _categoriesRepository.Add(newCat);
         _categoriesRepository.Commit();
         return(newCat.Id);
     }
     return(null);
 }