Пример #1
0
 public BaseResult CreateOrUpdateBusinessUnit(BusinessUnit bu)
 {
     bu.Name = bu.Name.Trim();
     if (bu.Id > 0) // Update
     {
         try
         {
             _businessUnits.Update(bu);
             return(new BaseResult
             {
                 Status = Status.Updated
             });
         }
         catch (StaleObjectStateException ex)
         {
             return(new BaseResult
             {
                 Status = Status.Conflict,
                 Message = "Beim Speichern ist ein Konflikt aufgetreten, laden sie die Daten neu"
             });
         }
         catch (Exception ex)
         {
             return(new BaseResult
             {
                 Status = Status.InternalServerError,
                 Message = ex.Message
             });
         }
     }
     else // Create
     {
         try
         {
             var saved = _businessUnits.FindByName(bu.Name);
             if (!(saved is null))
             {
                 return(new BaseResult
                 {
                     Status = Status.BadRequest,
                     Message = "Es existiert bereits eine Abteilung mit diesem Namen"
                 });
             }
             _businessUnits.Create(bu);
             return(new BaseResult
             {
                 Status = Status.Created
             });
         }
         catch (Exception ex)
         {
             return(new BaseResult
             {
                 Status = Status.InternalServerError,
                 Message = ex.Message
             });
         }
     }
 }
Пример #2
0
 public bool Create(BusinessUnit entity)
 {
     return(_businessUnitRepository.Create(entity));
 }