Exemple #1
0
        public virtual ActionResult Create(PropertyModel model)
        {
            _PropertyService.AddProperty(model);
            var sd = _uow.SaveChanges();

            return(null);
        }
Exemple #2
0
        public ActionResult Create(PropertyViewModel property)
        {
            var carrierId = Url.RequestContext.RouteData.Values["id"];

            if (ModelState.IsValid)
            {
                property.CarrierId = Convert.ToInt32(carrierId);
                _propertyService.AddProperty(Mapper.Map <PropertyDTO>(property));
            }

            return(RedirectToAction("Index", "Property", new { id = carrierId }));
        }
Exemple #3
0
        public async Task <IActionResult> Add(PropertyModel model)
        {
            try
            {
                await _propertyService.AddProperty(model);

                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception e)
            {
                return(RedirectToAction(nameof(Index)));
            }
        }
        public ActionResult Create([Bind(Include = "Name")] Property property)
        {
            _logger.InfoFormat("Create property with name [{0}]", property.Name);

            if (ModelState.IsValid)
            {
                _propertyService.AddProperty(property.Name);

                _logger.InfoFormat("Create property with name [{0}] was successful.", property.Name);
                return(RedirectToAction("Index"));
            }
            return(View(property));
        }
        public async Task <IActionResult> AddProperty([FromForm] PropertyCreateViewModel property)
        {
            if (property == null)
            {
                throw new ArgumentException($"{nameof(property)} can not be null");
            }
            if (ModelState.IsValid)
            {
                var propertyDto = _mapper.Map <PropertyCreateDto>(property);
                await _propertyService.AddProperty(propertyDto);

                return(Ok());
            }

            return(BadRequest());
        }
        public IHttpActionResult Post(CreatePropertyViewModel createModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }


            var propertyData = new Property();

            AutoMapper.Mapper.Map(createModel, propertyData);
            _propertyService.AddProperty(propertyData);


            var propertyViewModel = new PropertyViewModel();

            AutoMapper.Mapper.Map(propertyData, propertyViewModel);

            return(Created(
                       new Uri(Request.RequestUri + "api/properties" + propertyViewModel.Id),
                       propertyViewModel));
        }
        public async Task <IActionResult> Add(PropertyModel model)
        {
            // throw new NotImplementedException();
            //  Validate model
            if (!ModelState.IsValid)
            {
                return(View());
            }

            try
            {
                await _propertyService.AddProperty(model);

                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception e)
            {
                // Return an error message to accounts page
                ModelState.AddModelError("", e.Message);

                return(RedirectToAction(nameof(Index)));
            }
        }
Exemple #8
0
        public async Task ImportItemsFromFile(Admin admin, string folderToFile, HttpPostedFileBase file,
                                              string imagesFolder, bool logInfoNeeded)
        {
            await Task.Run(() =>
            {
                var fileName = _fileLoader.Load(folderToFile, file);

                var items = _importService.ImportItemsFromFile(Path.Combine(folderToFile, fileName));


                string logInfo = "";

                var categories = _categoryService.GetAllCategories();


                int addedCount = 0;
                for (int i = 0; i < items.Count; i++)
                {
                    if (items[i].Name == null)
                    {
                        logInfo += "<" + items[i].Name + "> is not added as name cannot be empty" +
                                   Environment.NewLine;
                        continue;
                    }
                    if (items[i].Title == null)
                    {
                        logInfo += "<" + items[i].Name + "> is not added as title cannot be empty" +
                                   Environment.NewLine;
                        continue;
                    }
                    if (items[i].SKUCode == null)
                    {
                        logInfo += "<" + items[i].Name + "> is not added as SKU code cannot be empty" +
                                   Environment.NewLine;
                        continue;
                    }
                    if (items[i].Price <= 0)
                    {
                        logInfo += "<" + items[i].Name + "> is not added as price <" +
                                   items[i].Price + "> is not valid" + Environment.NewLine;
                        continue;
                    }

                    var itemPropertiesToAdd = new HashSet <ItemProperty>();
                    var propertiesToAdd     = items[i].ItemProperties.ToList();

                    //NOTE: items[i].Category should be nulled
                    Category categoryToAdd = null;
                    if (!(string.IsNullOrWhiteSpace(items[i].Category.Name) || string.IsNullOrEmpty(items[i].Category.Name)) &&
                        (categoryToAdd = categories.FirstOrDefault(c => c.Name == items[i].Category.Name)) == null)
                    {
                        logInfo += "<" + items[i].Name + "> category does not exist is so it is added to db <" +
                                   items[i].Category.Name + ">" + Environment.NewLine;

                        var propertiesToAddToCategory = new List <int>();
                        foreach (var property in propertiesToAdd)
                        {
                            Property propertyInDB;
                            if (!(string.IsNullOrEmpty(property.Property.Name) || string.IsNullOrWhiteSpace(property.Property.Name)))
                            {
                                if ((propertyInDB = _propertyService.GetProperty(property.Property.Name)) == null)
                                {
                                    _propertyService.AddProperty(property.Property.Name);
                                    propertyInDB = _propertyService.GetProperty(property.Property.Name);
                                }
                                propertiesToAddToCategory.Add(propertyInDB.Id);
                            }
                        }

                        _categoryService.CreateCategory(items[i].Category.Name, propertiesToAddToCategory);
                        categories        = _categoryService.GetAllCategories();
                        categoryToAdd     = categories.FirstOrDefault(c => c.Name == items[i].Category.Name);
                        items[i].Category = null;
                    }


                    items[i].Category   = null;
                    items[i].CategoryId = categoryToAdd.Id;

                    var categoryProperties = categoryToAdd.Properties;


                    foreach (var categoryproperty in categoryProperties)
                    {
                        var propertyToAdd = propertiesToAdd.FirstOrDefault(x => x.Property.Name == categoryproperty.Name);
                        if (propertyToAdd == null)
                        {
                            propertyToAdd = new ItemProperty();
                        }
                        itemPropertiesToAdd.Add(new ItemProperty()
                        {
                            PropertyId = categoryproperty.Id, Value = propertyToAdd.Value
                        });
                    }


                    items[i].ItemProperties = itemPropertiesToAdd;

                    try
                    {
                        CreateItemWithImage(items[i], imagesFolder);
                        addedCount++;
                    }
                    catch (Exception e)
                    {
                        logInfo = "Unable to save item <" + items[i].Name + "> to database. Exception message: " + e.Message +
                                  Environment.NewLine;
                    }
                }
                if (logInfoNeeded)
                {
                    logInfo += addedCount + "/" + items.Count + " items were successfully added";

                    var email = new Email()
                    {
                        ToName         = admin.Name,
                        ToAddress      = admin.Email,
                        Subject        = "Import",
                        Body           = logInfo,
                        AttachmentPath = ""
                    };
                    _emailService.SendEmail(email);
                }
            });
        }
Exemple #9
0
 public IActionResult AddProperty(Property property)
 {
     //UserService service = new UserService();
     return(Ok(_propertyService.AddProperty(property)));
 }
Exemple #10
0
 public void Post([FromBody] PropertyDTO value)
 {
     _service.AddProperty(value);
 }