public IHttpActionResult Update(string name, FarmModel farm)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest(this.ModelState));
            }

            var userName = this.User.Identity.Name;

            var existingFarm = this.data
                               .Farms
                               .All()
                               .Where(a => a.Account == name && a.Deleted == false)
                               .FirstOrDefault();

            if (existingFarm == null)
            {
                return(this.BadRequest("Such farm does not exists or you have no authority to edit it!"));
            }

            existingFarm.Name    = farm.Name;
            existingFarm.Address = farm.Address;

            if (farm.Phones != null)
            {
                existingFarm.Phones = farm.Phones;
            }

            if (farm.Owner != null)
            {
                existingFarm.Owner = farm.Owner;
            }

            if (farm.Latitude != null)
            {
                existingFarm.Latitude = farm.Latitude;
            }

            if (farm.Longitude != null)
            {
                existingFarm.Longitude = farm.Longitude;
            }

            this.data.SaveChanges();

            farm.Id = existingFarm.Id;

            var newFarm = new
            {
                Id        = farm.Id,
                Name      = farm.Name,
                Address   = farm.Address,
                Owner     = farm.Owner,
                Phones    = farm.Phones,
                Latitude  = farm.Latitude,
                Longitude = farm.Longitude
            };

            return(this.Ok(newFarm));
        }
        public IHttpActionResult Update(string name, FarmModel farm)
        {
            if (!this.ModelState.IsValid)
            {
                return this.BadRequest(this.ModelState);
            }

            var userName = this.User.Identity.Name;

            var existingFarm = this.data
            .Farms
                                   .All()
                                   .Where(a => a.Account == name && a.Deleted == false)
                                   .FirstOrDefault();

            if (existingFarm == null)
            {
                return this.BadRequest("Such farm does not exists or you have no authority to edit it!");
            }

            existingFarm.Name = farm.Name;
            existingFarm.Address = farm.Address;

            if (farm.Phones != null)
            {
                existingFarm.Phones = farm.Phones;
            }

            if (farm.Owner != null)
            {
                existingFarm.Owner = farm.Owner;
            }

            if (farm.Latitude != null)
            {
                existingFarm.Latitude = farm.Latitude;
            }

            if (farm.Longitude != null)
            {
                existingFarm.Longitude = farm.Longitude;
            }

            this.data.SaveChanges();

            farm.Id = existingFarm.Id;

            var newFarm = new
            {
                Id = farm.Id,
                Name = farm.Name,
                Address = farm.Address,
                Owner = farm.Owner,
                Phones = farm.Phones,
                Latitude = farm.Latitude,
                Longitude = farm.Longitude
            };

            return this.Ok(newFarm);
        }
Example #3
0
        public async Task <IActionResult> Update(int id)
        {
            var farm = await _farmService.FindDetailAsync(new IdRequestFilter <long>
            {
                Id              = id,
                CanGetDeleted   = true,
                CanGetInactived = true
            });

            if (farm == null)
            {
                return(RedirectToNotFoundPage());
            }
            var model = new FarmModel()
            {
                Description  = farm.Description,
                CreatedDate  = farm.CreatedDate,
                UpdatedDate  = farm.UpdatedDate,
                UpdatedBy    = farm.UpdatedBy,
                UpdateById   = farm.UpdatedById,
                CreatedBy    = farm.CreatedBy,
                CreatedById  = farm.CreatedById,
                FarmTypeId   = farm.FarmTypeId,
                FarmTypeName = farm.FarmTypeName,
                Name         = farm.Name,
                Id           = farm.Id,
                StatusId     = (FarmStatus)farm.StatusId,
                Pictures     = farm.Pictures.Select(y => new PictureRequestModel()
                {
                    PictureId = y.Id
                }),
            };

            return(View(model));
        }
Example #4
0
        public FarmModel GetFarmCategoryList()
        {
            IMasterTablesDataAccess _repository = new MasterTablesDataAccess();
            FarmModel response = new FarmModel();

            response.FarmCategoryList = _repository.GetFarmCategoryList();
            return(response);
        }
Example #5
0
        public FarmModel GetFarmTypesList(FarmTypeModel model)
        {
            IMasterTablesDataAccess _repository = new MasterTablesDataAccess();
            FarmModel response = new FarmModel();

            response.FarmTypesList = _repository.GetFarmTypesList(model);
            return(response);
        }
Example #6
0
        private void AddFarmCell(AcPdfPTable table, FarmModel farm)
        {
            var cell = DefaultCell(table.ColorDark);

            cell.AddElement(new Phrase(farm.Ktidb, Fonts.Helvetica12BlackBold));
            cell.AddElement(new Phrase(farm.CompleteName, Fonts.Helvetica12BlackBold));
            cell.AddElement(new Phrase(farm.Address, Fonts.Helvetica10Black));
            cell.AddElement(new Phrase("Email: " + farm.Email, Fonts.Helvetica10Black));
            table.AddCell(cell);
        }
Example #7
0
        public async Task <IActionResult> Update(FarmModel model)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToErrorPage());
            }

            if (model.Id <= 0)
            {
                return(RedirectToErrorPage());
            }

            var exist = await _farmService.FindAsync(new IdRequestFilter <long>
            {
                Id              = model.Id,
                CanGetDeleted   = true,
                CanGetInactived = true
            });

            if (exist == null)
            {
                return(RedirectToErrorPage());
            }

            var farm = new FarmModifyRequest()
            {
                Id          = model.Id,
                UpdatedById = LoggedUserId,
                CreatedById = LoggedUserId,
                Name        = model.Name,
                Description = model.Description,
                FarmTypeId  = model.FarmTypeId
            };

            if (model.Pictures != null && model.Pictures.Any())
            {
                farm.Pictures = model.Pictures.Select(x => new PictureRequest()
                {
                    Base64Data  = x.Base64Data,
                    ContentType = x.ContentType,
                    FileName    = x.FileName,
                    Id          = x.PictureId
                });
            }

            farm.UpdatedById = LoggedUserId;
            await _farmService.UpdateAsync(farm);

            return(RedirectToAction(nameof(Detail), new { id = farm.Id }));
        }
        private void CompareExpectedResult(FarmModel result)
        {
            // Validate response
            Assert.Equal(result.Properties.HealthStatus, HealthStatus.Warning);


            Assert.Equal(60, result.Properties.Settings.SettingsPollingIntervalInSecond);
            Assert.Equal(80, result.Properties.Settings.HostStyleHttpPort);
            Assert.Equal(443, result.Properties.Settings.HostStyleHttpsPort);
            Assert.Equal("http://manage.wossportal.com;http://www.example.com", result.Properties.Settings.CorsAllowedOriginsList);
            Assert.Equal("contoso.com", result.Properties.Settings.DataCenterUriHostSuffixes);

            Assert.Equal("\\\\localhost\\db1\\settings", result.Properties.SettingsStore);
        }
        public ActionResult CreateUpdateFarm(Int32 id)
        {
            var farmModel = new FarmModel();

            farmModel.PurchasedDate = farmModel.StartDate = farmModel.EndDate = DateTime.Now;

            if (id > 0)
            {
                var farm = FarmManagementEntities.Farms.Single(x => x.Id == id);
                farmModel = farm.ToType <Farm, FarmModel>();

                farmModel.FarmStatus = Convert.ToInt32(farm.Status.ParseEnum <FarmStatus>());
            }

            return(PartialView("FarmPartial", farmModel));
        }
        public ActionResult CreateUpdateFarm(FarmModel farmModel)
        {
            if (!ModelState.IsValid)
            {
                return(ShowErrorMessage(GetModelErrors(ModelState)));
            }

            var farm = new Farm();

            if (farmModel.Id > 0)
            {
                farm = FarmManagementEntities.Farms.Single(x => x.Id == farmModel.Id);
            }

            farm.FarmName      = farmModel.FarmName;
            farm.Description   = farmModel.Description;
            farm.Address       = farmModel.Address;
            farm.TotalArea     = farmModel.TotalArea;
            farm.ActualPrice   = farmModel.ActualPrice;
            farm.TaxAmount     = farmModel.TaxAmount;
            farm.TotalValue    = farmModel.TotalValue;
            farm.PaperValue    = farmModel.PaperValue;
            farm.Rent          = farmModel.Rent;
            farm.Owner         = farmModel.Owner;
            farm.PurchasedDate = farmModel.PurchasedDate;
            farm.StartDate     = farmModel.StartDate;
            farm.EndDate       = farmModel.EndDate;
            farm.TotalMonths   = farmModel.TotalMonths;

            farm.Status = farmModel.FarmStatus.ToNullIfEmptyEnum <FarmStatus>();

            if (farmModel.Id == 0)
            {
                farm.InsertDate = DateTime.Now;
                FarmManagementEntities.Farms.Add(farm);
            }
            else
            {
                farm.UpdateDate = DateTime.Now;
            }

            FarmManagementEntities.SaveChanges();

            var message = string.Format(Constant.SuccessMessage, farmModel.Id > 0 ? "updated" : "added");

            return(ShowSuccessMessage(message));
        }
Example #11
0
        public IActionResult Create([FromBody] FarmModel model)
        {
            // map model to entity
            var farm = _mapper.Map <Farm>(model);

            try
            {
                // create farm
                _farmService.Create(farm);
                return(Ok());
            }
            catch (AppException ex)
            {
                // return error message if there was an exception
                return(BadRequest(new { message = ex.Message }));
            }
        }
Example #12
0
        public async Task <IHttpActionResult> Update([FromBody] FarmModel farm)
        {
            return(await ResultFactory.Create(ModelState, async arg =>
            {
                var result = await farmService.UpdateAsync(new FarmDto
                {
                    APIKey = farm.APIKey,
                    AreaStationSerialnum = farm.AreaStationSerialnum,
                    CompanySerialnum = farm.CompanySerialnum,
                    Name = farm.Name,
                    SysDepartmentSerialnum = farm.SysDepartmentSerialnum,
                    UploadPassword = farm.UploadPassword,
                    UpdateTime = DateTime.Now
                }) > 0;

                return new ApiResult(result ? ExceptionCode.Success : ExceptionCode.InternalError, "",
                                     null);
            }, farm, "success", "请检查请求参数"));
        }
Example #13
0
        public IActionResult Update(int id, [FromBody] FarmModel model)
        {
            // map model to entity and set id
            var farm = _mapper.Map <Farm>(model);

            farm.Id = id;

            try
            {
                // update farm
                _farmService.Update(farm);
                return(Ok());
            }
            catch (AppException ex)
            {
                // return error message if there was an exception
                return(BadRequest(new { message = ex.Message }));
            }
        }
Example #14
0
        private async Task <FarmModel> MapFarmResultToModelAsync(FarmResult farmResult)
        {
            var farm = new FarmModel()
            {
                FarmTypeId         = farmResult.FarmTypeId,
                FarmTypeName       = farmResult.FarmTypeName,
                Description        = farmResult.Description,
                Id                 = farmResult.Id,
                CreatedBy          = farmResult.CreatedBy,
                CreatedById        = farmResult.CreatedById,
                CreatedDate        = farmResult.CreatedDate,
                Name               = farmResult.Name,
                Address            = farmResult.Address,
                CreatedByPhotoCode = farmResult.CreatedByPhotoCode,
                Pictures           = farmResult.Pictures.Select(y => new PictureRequestModel()
                {
                    PictureId = y.Id
                }),
            };

            farm.CreatedByIdentityId = await _userManager.EncryptUserIdAsync(farm.CreatedById);

            return(farm);
        }
Example #15
0
 public async Task <FarmModel> UpdateFarmAsync(ClaimsPrincipal claimsPrincipal, [Service] IFarmResolver farmResolver, FarmModel criterias)
 {
     return(await farmResolver.UpdateFarmAsync(claimsPrincipal, criterias));
 }
Example #16
0
        public async Task <FarmModel> CreateFarmAsync(ClaimsPrincipal claimsPrincipal, FarmModel criterias)
        {
            var currentUserId = GetCurrentUserId(claimsPrincipal);
            var farm          = new FarmModifyRequest()
            {
                CreatedById = currentUserId,
                UpdatedById = currentUserId,
                Description = criterias.Description,
                Name        = criterias.Name,
                FarmTypeId  = criterias.FarmTypeId,
                Address     = criterias.Address,
                Pictures    = criterias.Pictures.Select(x => new PictureRequest()
                {
                    Base64Data  = x.Base64Data,
                    FileName    = x.FileName,
                    ContentType = x.ContentType,
                }),
            };

            var id = await _farmService.CreateAsync(farm);

            criterias.Id = id;
            return(criterias);
        }
Example #17
0
        public async Task <FarmModel> UpdateFarmAsync(ClaimsPrincipal claimsPrincipal, FarmModel criterias)
        {
            var exist = await _farmService.FindAsync(new IdRequestFilter <long>
            {
                Id = criterias.Id,
                CanGetInactived = true
            });

            if (exist == null)
            {
                throw new Exception("No article found");
            }

            var currentUserId = GetCurrentUserId(claimsPrincipal);

            if (currentUserId != exist.CreatedById)
            {
                throw new UnauthorizedAccessException();
            }

            var farm = new FarmModifyRequest()
            {
                Id          = criterias.Id,
                CreatedById = currentUserId,
                UpdatedById = currentUserId,
                Description = criterias.Description,
                Name        = criterias.Name,
                FarmTypeId  = criterias.FarmTypeId,
                Address     = criterias.Address,
            };

            if (criterias.Pictures != null && criterias.Pictures.Any())
            {
                farm.Pictures = criterias.Pictures.Select(x => new PictureRequest()
                {
                    Base64Data  = x.Base64Data,
                    ContentType = x.ContentType,
                    FileName    = x.FileName,
                    Id          = x.PictureId
                });
            }

            await _farmService.UpdateAsync(farm);

            return(criterias);
        }
Example #18
0
 public FarmResponse(FarmModel resource) : base(resource)
 {
 }
 public FarmResponse(FarmModel resource) : base(resource)
 {
 }
Example #20
0
        private void CompareExpectedResult(FarmModel result)
        {
            // Validate response 
            Assert.Equal(result.Properties.HealthStatus, HealthStatus.Warning);


            Assert.Equal(60, result.Properties.Settings.SettingsPollingIntervalInSecond);
            Assert.Equal(80, result.Properties.Settings.HostStyleHttpPort);
            Assert.Equal(443, result.Properties.Settings.HostStyleHttpsPort);
            Assert.Equal("http://manage.wossportal.com;http://www.example.com", result.Properties.Settings.CorsAllowedOriginsList);
            Assert.Equal("contoso.com", result.Properties.Settings.DataCenterUriHostSuffixes);

            Assert.Equal("\\\\localhost\\db1\\settings", result.Properties.SettingsStore);
        }