/// <summary>
        /// Converts from.
        /// </summary>
        /// <param name="estateModel">The estate model.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">estateModel</exception>
        public EstateViewModel ConvertFrom(EstateModel estateModel)
        {
            if (estateModel == null)
            {
                throw new ArgumentNullException(nameof(estateModel));
            }

            EstateViewModel viewModel = new EstateViewModel
            {
                EstateName = estateModel.EstateName,
                EstateId   = estateModel.EstateId
            };

            return(viewModel);
        }
Beispiel #2
0
        public async Task <ActionResult> DeleteAsync(string id)
        {
            if (id == null)
            {
                return(BadRequest());
            }

            EstateModel item = await _cosmosDbService.GetItemAsync(id);

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

            return(View(item));
        }
        public async Task <IActionResult> GetEstate(CancellationToken cancellationToken)
        {
            try
            {
                String accessToken = await this.HttpContext.GetTokenAsync("access_token");

                EstateModel estateDetails = await this.ApiClient.GetEstate(accessToken, this.User.Identity as ClaimsIdentity, cancellationToken);

                return(this.View("EstateDetails", this.ViewModelFactory.ConvertFrom(estateDetails)));
            }
            catch (Exception ex)
            {
                // Something went wrong creating the contract
                return(this.View("EstateDetails").WithWarning("Estate Details", Helpers.BuildUserErrorMessage("Error getting estate information")));
            }
        }
Beispiel #4
0
 public IHttpActionResult Put([FromBody] EstateModel model)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             return(BadRequest(ModelState));
         }
         _estateService.Update(model);
         return(Ok(model));
     }
     catch (Exception ec)
     {
         return(BadRequest(ec.Message));
     }
 }
        public async Task <IActionResult> GetOperatorListAsJson(CancellationToken cancellationToken)
        {
            try
            {
                String accessToken = await this.HttpContext.GetTokenAsync("access_token");

                EstateModel estate = await this.ApiClient.GetEstate(accessToken, this.User.Identity as ClaimsIdentity, cancellationToken);

                List <OperatorListViewModel> operatorViewModels = this.ViewModelFactory.ConvertFrom(estate.EstateId, estate.Operators);

                return(this.Json(operatorViewModels));
            }
            catch (Exception e)
            {
                return(this.Json(Helpers.GetErrorDataForDataTable <String>(Helpers.BuildUserErrorMessage("Error getting operator list"))));
            }
        }
 public IActionResult CreateEstate(EstateModel Model)
 {
     try
     {
         Model.UserID = Guid.Parse(HttpContext.Session.GetString("UserID"));
         string Token = HttpContext.Session.GetString("Token");
         this.estateHandler.Create(Model, Token);
         ViewBag.Rulesets = this.rulesetHandler.GetOwnedRuleset(Model.UserID, Token);
         ViewBag.Estates  = this.estateHandler.GetOwnedEstates(Model.UserID, Token);
         ViewBag.Message  = "Bolig Oprette";
         return(View("/Views/Landlord/Index.cshtml"));
     }
     catch (Exception)
     {
         ViewBag.Message = "Der er sket en fejl";
         return(View("/Views/Landlord/Estate.cshtml"));
     }
 }
Beispiel #7
0
        public void Update(Guid EstateID, EstateModel estate, Guid UserID, string Token)
        {
            var Estate = this.Context.Estates.Where(x => x.ID == estate.ID).FirstOrDefault();

            if (Estate == null)
            {
                throw new Exception("Estate not found");
            }

            if (Estate.UserID != UserID)
            {
                throw new Exception("Unauthorized");
            }

            if (!this.userHandler.AuthenticateUser(UserID, Token))
            {
                throw new Exception("Unauthorized");
            }

            var Ruleset = this.Context.Rulesets.Where(x => x.ID == estate.RulesetID).FirstOrDefault();

            if (Ruleset == null)
            {
                throw new Exception("Ruleset not found");
            }

            if (Ruleset.UserID != estate.UserID)
            {
                throw new Exception("You do not own that ruleset");
            }

            Estate.Name        = estate.Name;
            Estate.RulesetID   = estate.RulesetID;
            Estate.Description = estate.Description;
            Estate.Size        = estate.Size;
            Estate.StreetName  = estate.StreetName;
            Estate.HouseNumber = estate.HouseNumber;
            Estate.Floor       = estate.Floor;

            Context.SaveChanges();
        }
Beispiel #8
0
        public ActionResult Edit(EstateModel model, HttpPostedFileBase ImageFile)
        {
            if (!ModelState.IsValid)
            {
                return(null);
            }

            if (ImageFile != null)
            {
                if (model.Image != null)
                {
                    var currentImagePath = Server.MapPath("~" + Constants.UploadPath + model.Image);

                    if (System.IO.File.Exists(currentImagePath))
                    {
                        System.IO.File.Delete(currentImagePath);
                    }
                }

                var imageName = Guid.NewGuid() + ".jpg";
                ImageFile.SaveAs(Server.MapPath("~" + Constants.UploadPath + imageName));
                model.Image = imageName;
            }

            var estateDto = Mapper.Map <EstateDto>(model);
            int id;

            if (model.EstateId == 0)
            {
                var result = _estateService.Add(estateDto);
                id = result.EstateId;
            }
            else
            {
                var result = _estateService.Update(estateDto);
                id = result.EstateId;
            }

            return(RedirectToAction("Edit", new { id }));
        }
Beispiel #9
0
        public void Create(EstateModel estate, string Token)
        {
            var userhandler = new UserHandler(this.Context);

            if (!userhandler.AuthenticateUser(estate.UserID, Token))
            {
                throw new Exception("Unauthorized");
            }

            var user = this.Context.Users.Where(x => x.ID == estate.UserID).FirstOrDefault();

            if (user == null || user.Type != "landlord")
            {
                throw new Exception("Unauthorized");
            }

            var ruleset = Context.Rulesets.Where(x => x.ID == estate.RulesetID).FirstOrDefault();

            if (ruleset == null)
            {
                throw new Exception("ruleset not found");
            }

            var houseCheck = Context.Estates.Where(x =>
                                                   x.StreetName == estate.StreetName &&
                                                   x.HouseNumber == estate.HouseNumber &&
                                                   x.Floor == estate.Floor
                                                   ).FirstOrDefault();

            if (houseCheck != null)
            {
                throw new Exception("House already exists");
            }

            estate.ID = Guid.NewGuid();
            Context.Estates.Add(estate);
            this.Context.SaveChanges();
        }
        public async Task <IActionResult> GetOperatorListAsJson(CancellationToken cancellationToken)
        {
            try
            {
                // Search Value from (Search box)
                String searchValue = this.HttpContext.Request.Form["search[value]"].FirstOrDefault();

                String accessToken = await this.HttpContext.GetTokenAsync("access_token");

                EstateModel estate = await this.ApiClient.GetEstate(accessToken, this.User.Identity as ClaimsIdentity, cancellationToken);

                List <OperatorListViewModel> operatorViewModels = this.ViewModelFactory.ConvertFrom(estate.EstateId, estate.Operators);

                Expression <Func <OperatorListViewModel, Boolean> > whereClause = m => m.OperatorName.Contains(searchValue, StringComparison.OrdinalIgnoreCase);

                return(this.Json(Helpers.GetDataForDataTable(this.Request.Form, operatorViewModels, whereClause)));
            }
            catch (Exception e)
            {
                Logger.LogError(e);
                return(this.Json(Helpers.GetErrorDataForDataTable <String>("Error getting operator list")));
            }
        }
Beispiel #11
0
        public JsonResult ApplyTempData(EstateModel model)
        {
            MSGReturnModel <IEnumerable <ITreaItem> > result = new MSGReturnModel <IEnumerable <ITreaItem> >();
            var _detail = (List <EstateDetailViewModel>)Cache.Get(CacheList.ESTATEData);

            if (!_detail.Any())
            {
                result.DESCRIPTION = "無申請任何資料";
            }
            else if (Cache.IsSet(CacheList.TreasuryAccessViewData))
            {
                TreasuryAccessViewModel data = (TreasuryAccessViewModel)Cache.Get(CacheList.TreasuryAccessViewData);
                var _data = (EstateViewModel)Cache.Get(CacheList.ESTATEAllData);
                _data.vItem_Book = model;
                _data.vDetail    = _detail;
                List <EstateViewModel> _datas = new List <EstateViewModel>();
                _datas.Add(_data);
                if (data.vAccessType == Ref.AccessProjectTradeType.G.ToString() && !_detail.Any(x => x.vtakeoutFlag))
                {
                    result.DESCRIPTION = "無申請任何資料";
                }
                else
                {
                    result = Estate.ApplyAudit(_datas, data);
                    if (result.RETURN_FLAG && !data.vAplyNo.IsNullOrWhiteSpace())
                    {
                        new TreasuryAccessController().ResetSearchData();
                    }
                }
            }
            else
            {
                result.RETURN_FLAG = false;
                result.DESCRIPTION = Ref.MessageType.login_Time_Out.GetDescription();
            }
            return(Json(result));
        }
Beispiel #12
0
        public void Create(EstateModel model)
        {
            try
            {
                if (_estateRepository.NameExist(model))
                {
                    throw new Exception("Estate already exist");
                }

                //var estate = new Estate()
                //{
                //    Name = model.Name,
                //    Address = model.Address,
                //    City = model.City

                //};
                var estate = Mapper.Map <EstateModel, Estate>(model);
                _estateRepository.Insert(estate);
            }
            catch (Exception ec)
            {
                throw new Exception(ec.Message);
            }
        }
Beispiel #13
0
 public bool NameExist(EstateModel model)
 {
     return(Table.Any(c => c.Id != model.Id && model.Name.Equals(c.Name, StringComparison.OrdinalIgnoreCase)));
 }
 public async Task UpdateItemAsync(string id, EstateModel item)
 {
     await this._container.UpsertItemAsync <EstateModel>(item, new PartitionKey(id));
 }
 public async Task AddItemAsync(EstateModel item)
 {
     await this._container.CreateItemAsync <EstateModel>(item, new PartitionKey(item.Id));
 }