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 RepositoryActionResult <WaterSetting> DeleteWaterSetting(int growSettingId, int GrowPhaseSettingId,
                                                                        int waterSettingId, Guid currentUserGuid)
        {
            try
            {
                WaterSetting waterSetting =
                    _dbContext.WaterSetting.FirstOrDefault(ls => ls.GrowPhaseSetting.GrowSettingId == growSettingId &&
                                                           ls.GrowPhaseSettingId == GrowPhaseSettingId &&
                                                           ls.WaterSettingId == waterSettingId
                                                           &&
                                                           ls.GrowPhaseSetting.GrowSetting.UserGuid ==
                                                           currentUserGuid);

                if (waterSetting == null)
                {
                    return(new RepositoryActionResult <WaterSetting>(null, RepositoryActionStatus.NotFound));
                }

                _dbContext.WaterSetting.Remove(waterSetting);

                _dbContext.SaveChanges();
                return(new RepositoryActionResult <WaterSetting>(null, RepositoryActionStatus.Deleted));
            }
            catch (Exception ex)
            {
                return(new RepositoryActionResult <WaterSetting>(null, RepositoryActionStatus.Error, ex));
            }
        }
        public IHttpActionResult PostWaterSetting(int growSettingId, int GrowPhaseSettingId, WaterSettingDto waterSetting)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return BadRequest(ModelState);
                }

                Guid currentUserGuid = _userHelper.GetUserGuid();

                WaterSetting entity = _waterSettingFactory.PostWaterSetting(waterSetting);

                RepositoryActionResult<WaterSetting> result = _growSettingsRepository.PostWaterSetting(entity,
                    currentUserGuid);

                if (result.Status == RepositoryActionStatus.Created)
                {
                    // map to dto
                    WaterSettingDto newWaterSetting = _waterSettingFactory.GetWaterSetting(result.Entity);
                    waterSetting.WaterSettingId = entity.WaterSettingId;
                    //TODO: this is wrong return address, find out correct one and replace
                    return Created(Request.RequestUri
                                   + "/" + result.Entity.WaterSettingId, newWaterSetting);
                }

                throw new Exception();
            }
            catch (Exception)
            {
                return InternalServerError();
            }
        }
        public RepositoryActionResult <WaterSetting> PutWaterSetting(int growSettingId, int GrowPhaseSettingId,
                                                                     int waterSettingId,
                                                                     WaterSetting modifiedWaterSetting, Guid currentUserGuid)
        {
            if (modifiedWaterSetting.GrowPhaseSetting.GrowSetting.UserGuid != currentUserGuid)
            {
                return(new RepositoryActionResult <WaterSetting>(modifiedWaterSetting, RepositoryActionStatus.NotFound));
            }

            //_dbContext.Entry(modifiedWaterSetting).State = EntityState.Modified;

            try
            {
                _dbContext.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                if (!WaterSettingExists(waterSettingId))
                {
                    return(new RepositoryActionResult <WaterSetting>(null, RepositoryActionStatus.Error, ex));
                }
                throw;
            }
            return(new RepositoryActionResult <WaterSetting>(modifiedWaterSetting, RepositoryActionStatus.Updated));
        }
예제 #5
0
 private void initValues(WaterSetting mObj)
 {
     scroll.Value                 = mObj.Scroll;
     scroll2.Value                = mObj.Scroll2;
     scroll3.Value                = mObj.Scroll3;
     scroll4.Value                = mObj.Scroll4;
     shoreFalloff.Value           = mObj.ShoreFalloff;
     shoreScale.Value             = mObj.ShoreScale;
     speed.Value                  = mObj.Speed;
     reflectionFactorOffset.Value = mObj.ReflectionFactorOffset;
 }
예제 #6
0
 public WaterSettingDto GetWaterSetting(WaterSetting waterSetting)
 {
     try
     {
         return(new WaterSettingDto
         {
             WaterSettingId = waterSetting.WaterSettingId,
             TurnOnWatertTime = waterSetting.TurnOnWaterTime,
             TurnOffWaterTime = waterSetting.TurnOffWaterTime,
             GrowPhaseSettingId = waterSetting.GrowPhaseSettingId
         });
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        public IHttpActionResult PutWaterSetting(int growSettingId, int growPhaseSettingId, int waterSettingId,
            WaterSettingDto waterSetting)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return BadRequest(ModelState);
                }

                Guid currentUserGuid = _userHelper.GetUserGuid();

                WaterSetting originalEntity = _growSettingsRepository.GetWaterSetting(growSettingId, growPhaseSettingId,
                    waterSettingId, currentUserGuid);

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

                WaterSetting modifiedWaterSetting = _waterSettingFactory.PutWaterSetting(originalEntity, waterSetting);

                RepositoryActionResult<WaterSetting> result = _growSettingsRepository.PutWaterSetting(growSettingId,
                    growPhaseSettingId, waterSettingId, modifiedWaterSetting,
                    currentUserGuid);

                switch (result.Status)
                {
                    case RepositoryActionStatus.Updated:
                        return Ok(_waterSettingFactory.GetWaterSetting(modifiedWaterSetting));
                    case RepositoryActionStatus.Error:
                        return InternalServerError();
                    case RepositoryActionStatus.NotFound:
                        return NotFound();
                    case RepositoryActionStatus.NothingModified:
                        return Ok(_waterSettingFactory.GetWaterSetting(modifiedWaterSetting));
                    default:
                        return BadRequest();
                }
            }
            catch (Exception)
            {
                return InternalServerError();
            }
        }
예제 #8
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (objectToEdit != null && objectToEdit is WaterSetting)
            {
                WaterSetting obj = objectToEdit as WaterSetting;
                txtBaseObjectId.Text      = obj.BaseObjectId;
                txtBaseObjectName.Text    = obj.BaseObjectName;
                isEditingObj              = true;
                txtBaseObjectId.IsEnabled = false;

                initValues(obj);
                cancelRevert = (WaterSetting)Utils.DeepClone(obj);
            }
            else
            {
                WaterSetting ss = new WaterSetting();
                initValues(ss);
            }
        }
예제 #9
0
        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            if (objectToEdit == null)
            {
                objectToEdit = new WaterSetting();
            }

            WaterSetting obj = objectToEdit as WaterSetting;

            obj.BaseObjectId   = txtBaseObjectId.Text;
            obj.BaseObjectName = txtBaseObjectName.Text;

            //custom code
            obj.Scroll                 = (float)scroll.Value;
            obj.Scroll2                = (float)scroll2.Value;
            obj.Scroll3                = (float)scroll3.Value;
            obj.Scroll4                = (float)scroll4.Value;
            obj.ShoreFalloff           = (float)shoreFalloff.Value;
            obj.ShoreScale             = (float)shoreScale.Value;
            obj.Speed                  = (float)speed.Value;
            obj.ReflectionFactorOffset = (float)reflectionFactorOffset.Value;
            //custom code end

            obj.Category = objCategory;
            bool success = isEditingObj ? WorldData.UpdateObject(obj) : WorldData.AddObject(obj);

            if (!success)
            {
                MessageBox.Show(Application.Current.MainWindow, "ID already exists", "AddObject Failure", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.Cancel);
            }
            else
            {
                this.Close();
                if (parentWindow != null)
                {
                    parentWindow.Refresh();
                }
            }
        }
예제 #10
0
        public IHttpActionResult GetWaterSetting(int growSettingId, int growPhaseSettingId, int waterSettingId)
        {
            try
            {
                Guid currentUserGuid = _userHelper.GetUserGuid();

                WaterSetting waterSetting = _growSettingsRepository.GetWaterSetting(growSettingId, growPhaseSettingId,
                    waterSettingId,
                    currentUserGuid);

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

                return Ok(_waterSettingFactory.GetWaterSetting(waterSetting));
            }
            catch (Exception)
            {
                return InternalServerError();
            }
        }
예제 #11
0
 public WaterSetting PutWaterSetting(WaterSetting originalEntity, WaterSettingDto waterSetting)
 {
     originalEntity.TurnOffWaterTime = waterSetting.TurnOffWaterTime;
     originalEntity.TurnOnWaterTime  = waterSetting.TurnOnWatertTime;
     return(originalEntity);
 }