Exemple #1
0
        public bool Post(PropertyModel model)
        {
            var entity = new PropertyEntity
            {
                PropertyName = model.PropertyName,

                Adduser = (UserBase)_workContext.CurrentUser,

                Addtime = DateTime.Now,

                UpdUser = (UserBase)_workContext.CurrentUser,

                UpdTime = DateTime.Now,

//				Value = model.Value,

                Category = _categoryService.GetCategoryById(model.Category.Id)
            };

            if (_propertyService.Create(entity).Id > 0)
            {
                return(true);
            }
            return(false);
        }
Exemple #2
0
        public Property Create(Property property)
        {
            var retVal = _propertyService.Create(property);

            ClearCache();
            return(retVal);
        }
        public async Task <IActionResult> Create([FromBody] PropertyModel property)
        {
            var r = await _propertyService.Create(property);

            if (r)
            {
                return(Ok());
            }

            return(BadRequest());
        }
        public IActionResult Add(Property newProperty) // -> receive data from a HTML form
        {
            if (ModelState.IsValid)                    // all required fields are completed
            {
                // assign the user to the property(house)
                newProperty.AppUserId = _userManager.GetUserId(User);

                _propertyService.Create(newProperty);
                return(RedirectToAction(nameof(Index))); // -> Index();
            }

            GetPropertyTypes();
            return(View("Form"));
        }
Exemple #5
0
        public IHttpActionResult Post(webModel.Property property)
        {
            var moduleProperty = property.ToModuleModel();

            if (property.IsNew)
            {
                _propertyService.Create(moduleProperty);
            }
            else
            {
                _propertyService.Update(new moduleModel.Property[] { moduleProperty });
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemple #6
0
        public IActionResult Add(Property newProperty) // -> receive data from form
        {
            if (ModelState.IsValid)                    // all required fields are completed
            {
                // We should be able to add the new property
                _propertyService.Create(newProperty);
                // service receives the new property
                // service sent the new property to repository (saved)

                return(RedirectToAction(nameof(Index))); // -> Index(); method above
            }


            GetPropertyTypes();
            return(View("Form"));
        }
Exemple #7
0
        public IHttpActionResult CreateOrUpdateProperty(webModel.Property property)
        {
            var moduleProperty = property.ToCoreModel();

            if (property.IsNew)
            {
                CheckCurrentUserHasPermissionForObjects(CatalogPredefinedPermissions.Create, moduleProperty);

                _propertyService.Create(moduleProperty);
            }
            else
            {
                CheckCurrentUserHasPermissionForObjects(CatalogPredefinedPermissions.Update, moduleProperty);

                _propertyService.Update(new[] { moduleProperty });
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemple #8
0
        private void UpdateProperties(ICollection <Property> original, ICollection <Property> backup)
        {
            var toUpdate = new List <Property>();

            backup.CompareTo(original, EqualityComparer <Property> .Default, (state, x, y) =>
            {
                switch (state)
                {
                case EntryState.Modified:
                    toUpdate.Add(x);
                    break;

                case EntryState.Added:
                    _propertyService.Create(x);
                    break;
                }
            });
            _propertyService.Update(toUpdate.ToArray());
        }
        private void SaveProperties(VirtoData virtoData, ShopifyImportParams importParams,
                                    ShopifyImportNotification notification)
        {
            var propertiesProgress = notification.Progresses[PropertiesKey];

            notification.Description = "Saving properties";
            _notifier.Upsert(notification);

            var propertiesToCreate = new List <coreModel.Property>();
            var propertiesToUpdate = new List <coreModel.Property>();

            var existingProperties = _propertyService.GetCatalogProperties(importParams.VirtoCatalogId);

            foreach (var property in virtoData.Properties)
            {
                if (propertiesToCreate.All(p => p.Name != property.Name) &&
                    propertiesToUpdate.All(p => p.Name != property.Name))
                {
                    var existitngProperty = existingProperties.FirstOrDefault(c => c.Name == property.Name);
                    if (existitngProperty != null)
                    {
                        property.Id = existitngProperty.Id;
                        propertiesToUpdate.Add(property);
                    }
                    else
                    {
                        propertiesToCreate.Add(property);
                    }
                }
            }

            foreach (var property in propertiesToCreate)
            {
                try
                {
                    _propertyService.Create(property);
                }
                catch (Exception ex)
                {
                    propertiesProgress.ErrorCount++;
                    notification.ErrorCount++;
                    notification.Errors.Add(ex.ToString());
                    _notifier.Upsert(notification);
                }
                finally
                {
                    //Raise notification each notifyProductSizeLimit property
                    propertiesProgress.ProcessedCount++;
                    notification.Description = string.Format("Creating properties: {0} of {1} created",
                                                             propertiesProgress.ProcessedCount, propertiesProgress.TotalCount);
                    if (propertiesProgress.ProcessedCount % NotifySizeLimit == 0 ||
                        propertiesProgress.ProcessedCount + propertiesProgress.ErrorCount ==
                        propertiesProgress.TotalCount)
                    {
                        _notifier.Upsert(notification);
                    }
                }
            }

            if (propertiesToUpdate.Count > 0)
            {
                _propertyService.Update(propertiesToUpdate.ToArray());

                notification.Description = string.Format("Updating properties: {0} updated",
                                                         propertiesProgress.ProcessedCount = propertiesProgress.ProcessedCount + propertiesToUpdate.Count);
                _notifier.Upsert(notification);
            }
            virtoData.Properties.Clear();
            virtoData.Properties.AddRange(propertiesToCreate);
            virtoData.Properties.AddRange(propertiesToUpdate);
        }
Exemple #10
0
        public async Task <IActionResult> Create(PropertyDetailViewModel model, List <IFormFile> files)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByEmailAsync(User.Identity.Name);

                var property = new Property {
                    UserId           = user.Id,
                    Title            = model.Title,
                    Description      = model.Description,
                    Area             = model.Area,
                    BathroomCount    = model.BathroomCount,
                    BuildingAge      = model.BuildingAge,
                    FloorCount       = model.FloorCount,
                    HasBalcony       = model.HasBalcony,
                    HasStuff         = model.HasStuff,
                    IsInSite         = model.IsInSite,
                    Price            = model.Price,
                    RoomCount        = model.RoomCount,
                    WhichFloor       = model.WhichFloor,
                    StateId          = model.StateId,
                    PropertyCategory = model.PropertyCategory,
                    PropertyType     = model.PropertyType
                };
                _propertyService.Create(property);

                //Fotoğraf işlemleri
                if (files.Count > 0)
                {
                    foreach (var file in files.ToList())
                    {
                        if (file.Length > 0)
                        {
                            //Dosya ismini alıyoruz
                            var fileName = Path.GetFileName(file.FileName);
                            //Benzersiz isim tanımlıyoruz (Guid)
                            var uniqueFileName = Convert.ToString(Guid.NewGuid());
                            //Dosya uzantısını alıyouz
                            var fileExtension = Path.GetExtension(fileName);

                            var newFileName = String.Concat(uniqueFileName, fileExtension);

                            string wwwPath = _environment.WebRootPath;

                            string folderPath = Path.Combine(wwwPath, $"img/{property.PropertyId}");

                            if (!Directory.Exists(folderPath))
                            {
                                Directory.CreateDirectory(folderPath);
                            }

                            string filePath = Path.Combine(folderPath, newFileName);

                            using (FileStream fs = System.IO.File.Create(filePath))
                            {
                                file.CopyTo(fs);
                                fs.Flush();
                            }

                            _photoService.Create(new Photo
                            {
                                PhotoPath  = newFileName,
                                PropertyId = property.PropertyId
                            });
                        }
                    }
                }
                return(RedirectToRoute(new { controller = "Account", action = "UsersProperties", UserId = user.Id }));
            }
            return(View());
        }