public ActionResult Edit(long id, Guid?token)
        {
            if (!User.Identity.IsAuthenticated && token.HasValue)
            {
                var user = authAdapter.ValidateAuthToken(token.Value);

                if (user.StatusCode == 200)
                {
                    CustomAuthentication.SetAuthCookie(user.Result.Username, user.Result.UserId, true);
                    return(RedirectToAction("edit"));
                }
            }

            var request = this.propertyAdapter.GetProperty(id, User.Identity.Name);

            if (request.StatusCode != 200)
            {
                return(this.NotFoundException());
            }

            PropertyEditModel model = new PropertyEditModel(
                new PropertyEditInputModel(request.Result)
                );

            return(View(model));
        }
Example #2
0
        /// <summary>
        ///     属性编辑器。
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="propertyMetadata">实体属性原始数据。</param>
        /// <param name="entityDto">实体数据传输对象。</param>
        /// <returns></returns>
        public static MvcHtmlString PropertyEditor(this HtmlHelper helper, IEntityPropertyMetadata propertyMetadata,
                                                   object entityDto)
        {
            if (helper == null)
            {
                throw new ArgumentNullException(nameof(helper));
            }
            if (propertyMetadata == null)
            {
                throw new ArgumentNullException(nameof(propertyMetadata));
            }
            if (entityDto == null)
            {
                throw new ArgumentNullException(nameof(entityDto));
            }

            var model = new PropertyEditModel(propertyMetadata, entityDto);

            if (propertyMetadata.DataType == DataType.CustomDataType)
            {
                return(helper.Partial(propertyMetadata.PartialViewPath + propertyMetadata.CustomDataType + "Editor",
                                      model));
            }

            return(helper.Partial(propertyMetadata.PartialViewPath + propertyMetadata.DataType + "Editor", model));
        }
        public ActionResult Edit(PropertyEditInputModel input, string command)
        {
            if (ModelState.IsValid)
            {
                var request = this.propertyAdapter.UpdateProperty(input.ToBuilding());

                if (request.StatusCode == 200)
                {
                    if (command == "save")
                    {
                        string uri = string.Format(
                            "{0}/dashboard/property/manage/{1}",
                            Config.Hostname,
                            request.Result.BuildingId
                            );

                        return(Redirect(uri));
                    }

                    if (command == "list")
                    {
                        return(RedirectToAction("list", new { id = request.Result.BuildingId }));
                    }

                    HandleErrors(request);
                }
            }

            PropertyEditModel model = new PropertyEditModel(input);

            return(View(model));
        }
Example #4
0
        public ActionResult Edit(PropertyEditInputModel input, string command)
        {
            if (ModelState.IsValid)
            {
                var request = this.propertyAdapter.UpdateProperty(input.ToBuilding());

                if (request.StatusCode == 200)
                {
                    if (command == "save")
                    {
                        return(RedirectToAction("manage", new { id = request.Result.BuildingId }));
                    }

                    if (command == "list")
                    {
                        return(RedirectToAction("list", new { id = request.Result.BuildingId }));
                    }

                    HandleErrors(request);
                }
            }

            PropertyEditModel model = new PropertyEditModel(input);

            return(View(model));
        }
        private IdentityProperty ExtractEditFormData(PropertyEditModel formData)
        {
            var myIdetity = new IdentityProperty();

            myIdetity.Id                 = formData.Id;
            myIdetity.Name               = formData.Name;
            myIdetity.Icon               = formData.Icon;
            myIdetity.Status             = formData.Status;
            myIdetity.PropertyCategoryId = formData.PropertyCategoryId;

            return(myIdetity);
        }
        private PropertyEditModel RenderEditModel(IdentityProperty identity)
        {
            var editModel = new PropertyEditModel();

            editModel.Id                 = identity.Id;
            editModel.Name               = identity.Name;
            editModel.Icon               = identity.Icon;
            editModel.Status             = identity.Status;
            editModel.LangList           = identity.LangList;
            editModel.PropertyCategoryId = identity.PropertyCategoryId;

            return(editModel);
        }
        public ActionResult Edit(PropertyEditModel model)
        {
            if (!ModelState.IsValid)
            {
                string messages = string.Join("; ", ModelState.Values
                                              .SelectMany(x => x.Errors)
                                              .Select(x => x.ErrorMessage + x.Exception));
                this.AddNotification(messages, NotificationType.ERROR);
                return(View(model));
            }

            try
            {
                //Upload file
                //if (model.Files != null && model.Files[0] != null)
                //{
                //    var apiResult = CdnServices.UploadPropertyCoverAsync(model).Result;
                //    if (apiResult != null)
                //    {
                //        if (apiResult.Code == EnumCommonCode.Success)
                //        {
                //            var imagesList = JsonConvert.DeserializeObject<List<string>>(apiResult.Data.ToString());
                //            if (imagesList != null && imagesList.Count > 0)
                //            {
                //                model.Cover = imagesList[0];
                //            }
                //        }
                //    }
                //}

                //Begin db transaction
                var info = ExtractEditFormData(model);

                var isSuccess = _mainStore.Update(info);

                if (isSuccess)
                {
                    this.AddNotification(ManagerResource.LB_UPDATE_SUCCESS, NotificationType.SUCCESS);
                }
            }
            catch (Exception ex)
            {
                this.AddNotification(NotifSettings.Error_SystemBusy, NotificationType.ERROR);

                logger.Error("Failed for Edit Property request: " + ex.ToString());

                return(View(model));
            }

            return(RedirectToAction("Edit/" + model.Id));
        }
Example #8
0
        public ActionResult Edit(long id)
        {
            var request = this.propertyAdapter.GetProperty(id, User.Identity.Name);

            if (request.StatusCode != 200)
            {
                return(this.NotFoundException());
            }

            PropertyEditModel model = new PropertyEditModel(
                new PropertyEditInputModel(request.Result)
                );

            return(View(model));
        }
Example #9
0
        public ActionResult Edit(long id)
        {
            var status = this.propertyAdapter.GetPropertyListingInfo(id, User.Identity.Name);

            if (status.StatusCode != 200)
            {
                return(HttpNotFound());
            }

            PropertyEditModel model = new PropertyEditModel();

            model.Input          = status.Result;
            model.StepsAvailable = GetStepsAvailable(status.Result);

            return(View(model));
        }
Example #10
0
        public ActionResult UpdateProperty()
        {
            PropertyEditModel model = new PropertyEditModel();
            var id = Utils.ConvertToInt32(Request["Id"]);
            var propertyCategoryId = Utils.ConvertToInt32(Request["PropertyCategoryId"]);

            if (propertyCategoryId == 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            if (id > 0)
            {
                model.IsUpdate = true;
            }

            try
            {
                model.PropertyCategoryId = propertyCategoryId;
                if (id > 0)
                {
                    var storeProperty = GlobalContainer.IocContainer.Resolve <IStoreProperty>();

                    //Begin db transaction
                    var info = storeProperty.GetById(id);

                    if (info != null)
                    {
                        model.Id   = info.Id;
                        model.Code = info.Code;
                        model.Name = info.Name;
                    }
                }
            }
            catch (Exception ex)
            {
                this.AddNotification(NotifSettings.Error_SystemBusy, NotificationType.ERROR);

                logger.Error("Failed for Show UpdateProperty form request: " + ex.ToString());
            }

            return(PartialView("../PropertyCategory/_UpdateProperty", model));
        }
Example #11
0
        public ActionResult Edit(Building input)
        {
            if (ModelState.IsValid)
            {
                var status = this.propertyAdapter.UpdatePropertyListingInfo(User.Identity.Name, input);

                if (status.StatusCode == 200)
                {
                    return(RedirectToAction("terms", new { id = input.BuildingId }));
                }

                HandleErrors(status);
            }

            var buildingVal = this.propertyAdapter.GetPropertyListingInfo(input.BuildingId, User.Identity.Name);

            if (buildingVal.StatusCode != 200)
            {
                return(HttpNotFound());
            }

            // load user since it was not posted
            input.User = buildingVal.Result.User;

            PropertyEditModel model = new PropertyEditModel()
            {
                Input          = input,
                StepsAvailable = GetStepsAvailable(buildingVal.Result)
            };

            if (input.CustomAmenities == null)
            {
                input.CustomAmenities = new List <CustomAmenity>();
            }

            return(View(model));
        }
        public async Task <IActionResult> Update(PropertyEditModel model)
        {
            var property = await _propertyService.GetAsync(model.Id);

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

            if (ModelState.IsValid)
            {
                _mapper.Map(model, property);

                property.Modified = DateTime.UtcNow;

                await _propertyService.UpdateAsync(property);

                return(RedirectToAction(nameof(Details), new { id = property.Id }));
            }

            await PrepareModelAsync(model);

            return(View(model));
        }
Example #13
0
 public static PropertyEdit ToEntity(this PropertyEditModel createmodel, PropertyEdit destination)
 {
     return(createmodel.MapTo(destination));
 }
Example #14
0
 public static PropertyEdit ToEntity(this PropertyEditModel createmodel)
 {
     return(createmodel.MapTo <PropertyEditModel, PropertyEdit>());
 }
Example #15
0
        public ActionResult UpdateProperty(PropertyEditModel model)
        {
            var msg       = ManagerResource.LB_OPERATION_SUCCESS;
            var isSuccess = false;

            if (!ModelState.IsValid)
            {
                string messages = string.Join("; ", ModelState.Values
                                              .SelectMany(x => x.Errors)
                                              .Select(x => x.ErrorMessage + x.Exception));
                this.AddNotification(messages, NotificationType.ERROR);

                return(Json(new { success = isSuccess, title = ManagerResource.LB_NOTIFICATION, message = messages }));
            }

            try
            {
                //Begin db transaction
                var data = new IdentityProperty();
                data.PropertyCategoryId = model.PropertyCategoryId;
                data.Id     = model.Id;
                data.Code   = model.Code;
                data.Name   = model.Name;
                data.Status = (int)EnumStatus.Activated;

                var storeProperty = GlobalContainer.IocContainer.Resolve <IStoreProperty>();

                if (model.Id > 0)
                {
                    //Update
                    storeProperty.Update(data);

                    //Clear cache
                    CachingHelpers.ClearPropertyCategoryCache();
                }
                else
                {
                    //Add new
                    var newId = storeProperty.Insert(data);

                    if (newId > 0)
                    {
                        isSuccess = true;

                        //Clear cache
                        CachingHelpers.ClearPropertyCategoryCache();

                        return(Json(new { success = isSuccess, title = ManagerResource.LB_NOTIFICATION, message = ManagerResource.LB_OPERATION_SUCCESS, clientcallback = " location.reload()" }));
                    }
                }

                isSuccess = true;
            }
            catch (Exception ex)
            {
                this.AddNotification(NotifSettings.Error_SystemBusy, NotificationType.ERROR);

                logger.Error("Failed for UpdateProperty request: " + ex.ToString());

                return(Json(new { success = isSuccess, title = ManagerResource.LB_NOTIFICATION, message = NotifSettings.Error_SystemBusy }));
            }

            return(Json(new { success = isSuccess, title = ManagerResource.LB_NOTIFICATION, message = msg, clientcallback = " location.reload()" }));
        }