Beispiel #1
0
        public virtual IActionResult PostTower([FromBody] TowerViewModel towerViewModel)
        {
            try
            {
                towerViewModel.UserId = UserId;
                var existingTower = TowerRepository.Find(towerViewModel.TowerId);

                if (existingTower != null)
                {
                    return(new ObjectResult(new OperationResult {
                        IsSuccess = false, ErrorMessage = "Tower is already exist"
                    }));
                }

                var towerModel = towerViewModel.Adapt <TowerViewModel, Tower>();
                TowerRepository.Add(towerModel);

                return(new ObjectResult(new OperationResult {
                    IsSuccess = true, ErrorMessage = "Created Successfully"
                }));
            }
            catch (Exception ex)
            {
                return(new ObjectResult(new OperationResult {
                    IsSuccess = false, ErrorMessage = ex.Message
                }));
            }
        }
Beispiel #2
0
        public virtual IActionResult PutTower([FromBody] TowerViewModel towerViewModel)
        {
            try
            {
                towerViewModel.UserId = UserId;
                var existingTower = TowerRepository.Find(towerViewModel.TowerId);

                if (existingTower != null)
                {
                    if (towerViewModel.TowerId > 0)
                    {
                        towerViewModel.Adapt(existingTower);
                        TowerRepository.Update(existingTower);

                        return(new ObjectResult(new OperationResult {
                            IsSuccess = true, ErrorMessage = "Tower Updated Successfully"
                        }));
                    }
                    else
                    {
                        return(new ObjectResult(new OperationResult {
                            IsSuccess = false, ErrorMessage = "Not Updated"
                        }));
                    }
                }
                else
                {
                    return(new ObjectResult(new OperationResult {
                        IsSuccess = false, ErrorMessage = "tower does not exist"
                    }));
                }
            }
            catch (Exception ex)
            {
                return(new ObjectResult(new OperationResult {
                    IsSuccess = false, ErrorMessage = ex.Message
                }));
            }
        }