コード例 #1
0
        public IHttpActionResult PostGrowPhaseSetting(GrowPhaseSettingDto growPhaseSetting)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                Guid currentUserGuid = _userHelper.GetUserGuid();

                GrowPhaseSetting entity = _GrowPhaseSettingFactory.PostGrowPhaseSetting(growPhaseSetting);

                RepositoryActionResult <GrowPhaseSetting> result = _growSettingsRepository.PostGrowPhaseSetting(entity,
                                                                                                                currentUserGuid);

                if (result.Status == RepositoryActionStatus.Created)
                {
                    // map to dto
                    GrowPhaseSettingDto newGrowPhaseSetting = _GrowPhaseSettingFactory.GetGrowPhaseSetting(result.Entity);
                    growPhaseSetting.GrowPhaseSettingId = entity.GrowPhaseSettingId;
                    //TODO: this is wrong return address, find out correct one and replace
                    return(Created(Request.RequestUri
                                   + "/" + result.Entity.GrowSettingId, newGrowPhaseSetting));
                }

                throw new Exception();
            }
            catch (Exception)
            {
                return(InternalServerError());
            }
        }
コード例 #2
0
 public GrowPhaseSetting PutGrowPhaseSetting(GrowPhaseSetting originalEntity, GrowPhaseSettingDto GrowPhaseSetting)
 {
     originalEntity.GrowPhaseName = GrowPhaseSetting.GrowPhaseName;
     originalEntity.Duration      = GrowPhaseSetting.Duration;
     originalEntity.PhaseNotes    = GrowPhaseSetting.PhaseNotes;
     //originalEntity.PhaseOrder = GrowPhaseSetting.PhaseOrder; Need to figure a way so that user cant f**k it up if they mess around with fiddler etc
     return(originalEntity);
 }
コード例 #3
0
 public GrowPhaseSetting PostGrowPhaseSetting(GrowPhaseSettingDto GrowPhaseSetting)
 {
     return(new GrowPhaseSetting
     {
         GrowPhaseName = GrowPhaseSetting.GrowPhaseName,
         Duration = GrowPhaseSetting.Duration,
         PhaseNotes = GrowPhaseSetting.GrowPhaseName,
         GrowSettingId = GrowPhaseSetting.GrowSettingId,
         PhaseOrder = GrowPhaseSetting.PhaseOrder
     });
 }
コード例 #4
0
        public IHttpActionResult PutGrowPhaseSetting(int growSettingId, int growPhaseSettingId, GrowPhaseSettingDto growPhaseSetting)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                Guid currentUserGuid = _userHelper.GetUserGuid();

                GrowPhaseSetting originalEntity = _growSettingsRepository.GetGrowPhaseSetting(growSettingId, growPhaseSettingId,
                                                                                              currentUserGuid);

                if (originalEntity == null)
                {
                    return(NotFound());
                }

                GrowPhaseSetting modifiedGrowPhaseSetting = _GrowPhaseSettingFactory.PutGrowPhaseSetting(originalEntity,
                                                                                                         growPhaseSetting);

                RepositoryActionResult <GrowPhaseSetting> result = _growSettingsRepository.PutGrowPhaseSetting(
                    growPhaseSettingId, modifiedGrowPhaseSetting,
                    currentUserGuid);

                switch (result.Status)
                {
                case RepositoryActionStatus.Updated:
                    return(Ok(_GrowPhaseSettingFactory.GetGrowPhaseSetting(modifiedGrowPhaseSetting)));

                case RepositoryActionStatus.Error:
                    return(InternalServerError());

                case RepositoryActionStatus.NotFound:
                    return(NotFound());

                case RepositoryActionStatus.NothingModified:
                    return(Ok(_GrowPhaseSettingFactory.GetGrowPhaseSetting(modifiedGrowPhaseSetting)));

                default:
                    return(BadRequest());
                }
            }
            catch (Exception)
            {
                return(InternalServerError());
            }
        }