public IHttpActionResult PostUserGrow(GrowSettingDto userGrow) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Guid currentUserGuid = _userHelper.GetUserGuid(); GrowSetting entity = _userGrowFactory.PostGrowSetting(userGrow, currentUserGuid); RepositoryActionResult <GrowSetting> result = _growSettingsRepository.PostGrowSetting(entity); if (result.Status == RepositoryActionStatus.Created) { // map to dto GrowSettingDto newUserGrow = _userGrowFactory.GetGrowSetting(result.Entity); userGrow.GrowSettingId = entity.GrowSettingId; return(Created(Request.RequestUri + "/" + result.Entity.GrowSettingId, newUserGrow)); } throw new Exception(); } catch (Exception) { return(InternalServerError()); } }
public RepositoryActionResult <WaterSetting> PostWaterSetting(WaterSetting entity, Guid currentUserGuid) { try { GrowSetting growSetting = GetGrowSetting(entity.GrowPhaseSetting.GrowSettingId, currentUserGuid); if (growSetting == null) { return(new RepositoryActionResult <WaterSetting>(entity, RepositoryActionStatus.NotFound)); } if (growSetting.UserGuid != currentUserGuid) { return(new RepositoryActionResult <WaterSetting>(entity, RepositoryActionStatus.NotFound)); } _dbContext.WaterSetting.Add(entity); int result = _dbContext.SaveChanges(); if (result > 0) { return(new RepositoryActionResult <WaterSetting>(entity, RepositoryActionStatus.Created)); } return(new RepositoryActionResult <WaterSetting>(entity, RepositoryActionStatus.NothingModified, null)); } catch (Exception ex) { return(new RepositoryActionResult <WaterSetting>(null, RepositoryActionStatus.Error, ex)); } }
public GrowSettingDto GetGrowSetting(GrowSetting growSetting) { return(new GrowSettingDto { GrowSettingId = growSetting.GrowSettingId, GrowSettingName = growSetting.GrowSettingName, GrowSettingNotes = growSetting.GrowSettingNotes, CreateDateTime = growSetting.CreateDateTime, SystemDefaultGrowSetting = growSetting.SystemDefaultGrowSetting, GrowPhaseSetting = growSetting.GrowPhaseSetting.Select(e => _GrowPhaseSettingFactory.GetGrowPhaseSetting(e)).ToList() }); }
public IHttpActionResult PutUserGrow(int growSettingId, GrowSettingDto userGrow) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Guid currentUserGuid = _userHelper.GetUserGuid(); GrowSetting originalEntity = _growSettingsRepository.GetGrowSetting(growSettingId, currentUserGuid); if (originalEntity == null) { return(NotFound()); } GrowSetting modifiedGrowSetting = _userGrowFactory.PutGrowSetting(originalEntity, userGrow); RepositoryActionResult <GrowSetting> result = _growSettingsRepository.PutGrowSetting(growSettingId, modifiedGrowSetting, currentUserGuid); switch (result.Status) { case RepositoryActionStatus.Updated: return(Ok(_userGrowFactory.GetGrowSetting(modifiedGrowSetting))); case RepositoryActionStatus.Error: return(InternalServerError()); case RepositoryActionStatus.NotFound: return(NotFound()); case RepositoryActionStatus.NothingModified: return(Ok(_userGrowFactory.GetGrowSetting(modifiedGrowSetting))); default: return(BadRequest()); } } catch (Exception) { return(InternalServerError()); } }
public RepositoryActionResult <GrowSetting> PostGrowSetting(GrowSetting entity) { try { _dbContext.GrowSetting.Add(entity); int result = _dbContext.SaveChanges(); if (result > 0) { return(new RepositoryActionResult <GrowSetting>(entity, RepositoryActionStatus.Created)); } return(new RepositoryActionResult <GrowSetting>(entity, RepositoryActionStatus.NothingModified, null)); } catch (Exception ex) { return(new RepositoryActionResult <GrowSetting>(null, RepositoryActionStatus.Error, ex)); } }
public IHttpActionResult GetUserGrow(int growSettingId) { try { Guid currentUserGuid = _userHelper.GetUserGuid(); GrowSetting growSetting = _growSettingsRepository.GetGrowSetting(growSettingId, currentUserGuid); if (growSetting == null) { return(NotFound()); } return(Ok(_userGrowFactory.GetGrowSetting(growSetting))); } catch (Exception) { return(InternalServerError()); } }
public RepositoryActionResult <GrowSetting> DeleteGrowSetting(int growSettingId, Guid currentUserGuid) { try { GrowSetting growSetting = _dbContext.GrowSetting.FirstOrDefault( ug => ug.GrowSettingId == growSettingId && ug.UserGuid == currentUserGuid); if (growSetting != null) { _dbContext.GrowSetting.Remove(growSetting); _dbContext.SaveChanges(); return(new RepositoryActionResult <GrowSetting>(null, RepositoryActionStatus.Deleted)); } return(new RepositoryActionResult <GrowSetting>(null, RepositoryActionStatus.NotFound)); } catch (Exception ex) { return(new RepositoryActionResult <GrowSetting>(null, RepositoryActionStatus.Error, ex)); } }
public GrowSetting PutGrowSetting(GrowSetting originalEntity, GrowSettingDto userGrow) { originalEntity.GrowSettingName = userGrow.GrowSettingName; originalEntity.GrowSettingNotes = userGrow.GrowSettingNotes; return(originalEntity); }
public RepositoryActionResult <GrowSetting> PutGrowSetting(int growSettingId, GrowSetting modifiedGrowSetting, Guid currentUserGuid) { if (modifiedGrowSetting.UserGuid != currentUserGuid) { _dbContext.Entry(modifiedGrowSetting).State = EntityState.Unchanged; return(new RepositoryActionResult <GrowSetting>(modifiedGrowSetting, RepositoryActionStatus.NotFound)); } //_dbContext.Entry(modifiedUserGrow).State = EntityState.Modified; try { _dbContext.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { if (!UserGrowExists(growSettingId)) { return(new RepositoryActionResult <GrowSetting>(null, RepositoryActionStatus.Error, ex)); } throw; } return(new RepositoryActionResult <GrowSetting>(modifiedGrowSetting, RepositoryActionStatus.Updated)); }