public IActionResult Create(CreateItemViewModel model)
        {
            if (ModelState.IsValid)
            {
                string UniqueFileName = ProcessUploadedFile(model);

                PubItems newItem = _context.AddPubItem(new PubItems()
                {
                    ItemName        = model.ItemName,
                    ItemType        = model.ItemType,
                    ItemPrice       = model.ItemPrice,
                    ItemImagePath   = UniqueFileName,
                    ItemDescription = model.ItemDescription,
                    ItemOnSale      = model.ItemOnSale,
                    ItemStock       = model.ItemStock,
                });
                if (!(newItem == null))
                {
                    return(RedirectToAction("Details", new { id = newItem.ItemId }));
                }
                else
                {
                    ModelState.AddModelError("", "An error occured, could not create a new item.");
                    //ERROR: item was not added
                }
            }
            return(View(model));
        }
Beispiel #2
0
        public ActionResult Create([Bind(Include = "Id,Name,Description,Price, Shop")] CreateItemViewModel model)
        {
            if (ModelState.IsValid)
            {
                Item item = new Item();

                using (DataContext ctx = new DataContext())
                {
                    item.Name        = model.Name;
                    item.Price       = model.Price;
                    item.Description = model.Description;
                    item.Shop        = ctx.Shops.Find(model.Shop.Id);

                    item.CreatedAt      = DateTime.Now;
                    item.CreatedBy      = 0;
                    item.LastModifiedAt = DateTime.Now;
                    item.LastModifiedBy = 0;
                    item.IsActive       = true;

                    ctx.Items.Add(item);
                    ctx.SaveChanges();
                    return(RedirectToAction("ViewItemsByShop", new { shopId = model.Shop.Id }));
                }
            }

            return(View(model));
        }
Beispiel #3
0
        public ActionResult CreateItem(CreateItemViewModel viewModel)
        {
            // Tries to save the new OrderItem record
            try
            {
                if (ModelState.IsValid)
                {
                    // Add new user's record to db
                    db.OrderItem.Add(viewModel.OrderItem);

                    // Save user's object
                    db.SaveChanges();

                    // Message to handle Create's status result
                    TempData["success"] = "Order Item created successfully";

                    return(RedirectToAction("Details", new { id = viewModel.OrderItem.OrderId }));
                }
                return(View(viewModel));
            }
            catch (Exception)
            {
                // Message to handle Create's status result
                TempData["danger"] = "Order Item was not created";

                return(RedirectToAction("Details", new { id = viewModel.OrderItem.OrderId }));
            }
        }
Beispiel #4
0
        public async Task <ActionResult> EditItemPost(CreateItemViewModel itemViewModel)
        {
            if (ModelState.IsValid)
            {
                Item item = await DbManager.Items.FirstAsync(r => r.ItemId == itemViewModel.ItemId);

                item.IsAvailable = itemViewModel.IsAvailable;
                item.Name        = itemViewModel.Name;
                item.UnitPrice   = Convert.ToDecimal(itemViewModel.UnitPrice, new CultureInfo("en-US"));

                if (itemViewModel.Image != null)
                {
                    item.Image = new ImageHelper().ProcessFileToImage(itemViewModel.Image);
                    if (item.Image == null)
                    {
                        ViewBag.Message = "Error while uploading the file";
                    }
                    else
                    {
                        ViewBag.Message = "File uploaded successfully";
                    }
                }
                await DbManager.SaveChangesAsync();
            }
            return(View("EditItem", new { id = itemViewModel.ItemId }));
        }
Beispiel #5
0
        public IActionResult CreateNewItem(CreateItemViewModel model)
        {
            IItemCollection itemCollection = _itemFactory.ItemCollection();

            itemCollection.CreateItem(new Item(model.Name, model.Description, model.Type, model.IsUnique));
            return(RedirectToAction("Index", "Item"));
        }
Beispiel #6
0
        public ActionResult CreateItem(DetailsEventViewModel model)
        {
            int id   = model.Id;
            var evnt = service.FindEventById(model.Id);

            CreateItemViewModel viewModel = new CreateItemViewModel
            {
                EventId     = id,
                Title       = "",
                Description = ""
            };

            List <SelectListItem> categories = new List <SelectListItem>();

            foreach (var item in evnt.Components)
            {
                if (item is Category)
                {
                    categories.Add(new SelectListItem {
                        Text = item.Title, Value = item.Id.ToString()
                    });
                }
            }

            viewModel.Categories = categories;

            return(View(viewModel));
        }
Beispiel #7
0
        // GET: Item/Create
        public async Task <ActionResult> Create(CreateItemViewModel model)
        {
            HttpResponseMessage responseMessage = await client.GetAsync("api/Item/getItemCategories");

            var ItemCategoryResponse = responseMessage.Content.ReadAsStringAsync().Result;

            var itemCategoriesResponse = JsonConvert.DeserializeObject <ItemCategoriesResponse>(ItemCategoryResponse);

            var categoriesList = new List <SelectListItem>();

            foreach (var category in itemCategoriesResponse.ItemCategories)
            {
                categoriesList.Add(new SelectListItem
                {
                    Value = category.Id.ToString(),
                    Text  = category.Name
                });
            }

            model.ItemCategories = categoriesList;

            if (ModelState.IsValid)
            {
                return(await CreateItem(model));
            }
            else
            {
                return(View(model));
            }
        }
        public IActionResult Create(CreateItemViewModel input)
        {
            var validator        = new CreateItemValidator();
            var validationResult = validator.Validate(input);

            if (!validationResult.IsValid)
            {
                foreach (var error in validationResult.Errors)
                {
                    input.ValidationErrors.Add(error.ToString());
                }

                return(View(input));
            }

            var image = new Image();

            if (input.Image != null)
            {
                using (var memoryStream = new MemoryStream())
                {
                    input.Image.CopyTo(memoryStream);
                    image.BinaryFile = memoryStream.ToArray();
                }

                image.ContentType = input.Image.ContentType;
                _imageService.Insert(image);
            }

            input.Item.CreatedinUtc = DateTime.UtcNow;
            input.Item.ImageId      = image.Id;
            _catalogService.Insert(input.Item);

            return(RedirectToAction(nameof(Index)));
        }
        // GET: Items
        public async Task <ActionResult> Index()
        {
            var itemsCategories = new CreateItemViewModel();

            itemsCategories.CategoryList = db.Categories;
            itemsCategories.ItemList     = db.Items;
            return(View(itemsCategories));
        }
Beispiel #10
0
        public void AddItem(CreateItemViewModel model)
        {
            using (var context = new HardwareShopContext())
            {
                var newItem = Mapper.Map <Item>(model);

                context.Items.Add(newItem);
                context.SaveChanges();
            }
        }
Beispiel #11
0
        public ActionResult Create()
        {
            var subCategories = this.itemService.GetAllSubCategories();
            var model         = new CreateItemViewModel()
            {
                SubCategories = subCategories
            };

            return(this.View(model));
        }
Beispiel #12
0
        public async Task <IActionResult> CreateAsync([FromBody] CreateItemViewModel createItemViewModel)
        {
            var createItemDto = _mapper.Map <CreateItemDto>(createItemViewModel);

            var createdItemDto = await _itemService.CreateAsync(createItemDto);

            var createdItemViewModel = _mapper.Map <ItemViewModel>(createdItemDto);

            return(Ok(createdItemViewModel));
        }
Beispiel #13
0
        // GET: Items/Create
        public ActionResult Create()
        {
            var model = new CreateItemViewModel();

            model.Projects = _db.Projects.Select(c => new SelectListItem {
                Text = c.Name, Value = c.Id.ToString()
            });

            return(View(model));
        }
        public IActionResult Create()
        {
            CreateItemViewModel vm = new CreateItemViewModel
            {
                TagSelect = _context.Tags.Select(x => new SelectListItem {
                    Selected = false, Text = x.Description, Value = x.Id.ToString()
                }).ToList()
            };

            return(View(vm));
        }
Beispiel #15
0
        // GET: Item/Create
        public ActionResult Create(int shopId)
        {
            CreateItemViewModel model = new CreateItemViewModel();

            using (DataContext ctx = new DataContext())
            {
                model.Shop   = ctx.Shops.Find(shopId);
                model.Images = new List <Image>();
            }
            return(View(model));
        }
Beispiel #16
0
        public ActionResult Create(CreateItemViewModel createModel)
        {
            if (!this.ModelState.IsValid)
            {
                createModel.SubCategories = this.itemService.GetAllSubCategories();
                return(this.View(createModel));
            }

            this.itemService.AddItem(createModel);
            return(this.RedirectToAction("Index", "Home"));
        }
Beispiel #17
0
        public ActionResult CreateItem(CreateItemViewModel model)
        {
            int    parentId;
            string selectedCategory = model.SelectedCategory;

            if (selectedCategory != null || selectedCategory != "")
            {
                Int32.TryParse(selectedCategory, out parentId);
                service.AddItemToCategory(model.EventId, parentId, model.Amount, model.Title, model.Description);
            }

            return(RedirectToAction("Details", new { id = model.EventId }));
        }
        public IActionResult CreateItem(IEnumerable <int> CategoryIds, IEnumerable <int> ManufacturerIds,
                                        CreateItemViewModel itemToCreate)
        {
            using (var client = new HttpClient())
            {
                var item = new Item()
                {
                    Id          = itemToCreate.Item.Id,
                    Description = itemToCreate.Item.Description,
                    Title       = itemToCreate.Item.Title,
                    Price       = itemToCreate.Item.Price,
                    Color       = itemToCreate.Item.Color,
                    Weight      = itemToCreate.Item.Weight,
                    Size        = itemToCreate.Item.Size


                                  //books?authId=?&authId=?&catId=?
                };

                var uriParameters = GetManufacturersCategoriesUri(ManufacturerIds.ToList(), CategoryIds.ToList());

                client.BaseAddress = new Uri("http://localhost:62352/api/");
                var responseTask = client.PostAsJsonAsync($"items?{uriParameters}", item);
                responseTask.Wait();

                var result = responseTask.Result;

                if (result.IsSuccessStatusCode)
                {
                    var readTaskNewItem = result.Content.ReadAsAsync <Item>();
                    readTaskNewItem.Wait();

                    var newItem = readTaskNewItem.Result;

                    TempData["SuccessMessage"] = $"Item {item.Title} was successfully created.";
                    return(RedirectToAction("GetItemById", new { itemId = newItem.Id }));
                }
            }

            var categoryList     = new CategoriesList(_categoryRepository.GetCategories().ToList());
            var manufacturerList = new ManufacturersList(_manufacturerRepository.GetManufacturers().ToList());

            itemToCreate.CategorySelectListItems     = categoryList.GetCategoriesList(CategoryIds.ToList());
            itemToCreate.ManufacturerSelectListItems = manufacturerList.GetManufacturersList(ManufacturerIds.ToList());
            itemToCreate.CategoryIds     = CategoryIds.ToList();
            itemToCreate.ManufacturerIds = ManufacturerIds.ToList();

            return(View(itemToCreate));
        }
Beispiel #19
0
        // GET: Create
        public async Task <ActionResult> Create()
        {
            var itemImageService = CreateItemImageService();
            var images           = await itemImageService.GetItemImages();

            var viewModel = new CreateItemViewModel();

            viewModel.Images = images.OrderBy(n => n.FileName).Select(i => new SelectListItem
            {
                Text  = i.FileName,
                Value = i.Id.ToString()
            });

            return(View(viewModel));
        }
Beispiel #20
0
        public async Task <ViewResult> Create()
        {
            using (var client = new OnebrbApi())
            {
                client.BaseUri = new Uri(_apiOptions.BaseAddress, UriKind.Absolute);
                var response = await client.GetAllCategoriesAsync();

                var viewModel = new CreateItemViewModel
                {
                    Categories = this._mapper.Map <ICollection <CategoryModel> >(response.Body)
                };

                return(View(viewModel));
            }
        }
        public ShellWindowViewModel(IConfigurationService configurationService, CreateItemViewModel creator, HistoryListViewModel historyList, SettingsWindowManager settingsManager)
        {
            _settingsManager    = settingsManager;
            _configurationAgent = configurationService.GetConfigurationAgent <ShellConfiguration>(ApplicationConfigurations.ShellConfiguration, this);

            _subscriptions = _configurationAgent.Updated.ObserveOnDispatcher().Do(x => { RefreshConfig(); }).Subscribe();

            Creator     = creator;
            HistoryList = historyList;

            ShowSettingsCommand = ReactiveCommand.Create(() => { _settingsManager.ShowSettingsWindow(); });

            RefreshConfig();

            PropertyChanged += (sender, e) => { PersistConfig(); };
        }
Beispiel #22
0
        public IActionResult Create([FromBody] CreateItemViewModel viewModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest("Model is not valid"));
            }

            this.createItemCommand.ItemToCreate = new Item()
            {
                TypeId           = viewModel.TypeId,
                Name             = viewModel.Name,
                RoomNumber       = viewModel.RoomNumber,
                ResponsibleEmail = viewModel.ResponsibleEmail
            };
            this.createItemCommand.Execute();
            return(this.Ok());
        }
        public async Task <IActionResult> Create([FromForm] CreateItemViewModel model)
        {
            if (ModelState.IsValid)
            {
                var item = new Item
                {
                    Id          = Guid.NewGuid(),
                    Category    = model.Category,
                    Name        = model.Name,
                    Description = model.Description?.Replace(Environment.NewLine, "<br/>"),
                    Weight      = model.Weight,
                    WC          = model.WC,
                    AC          = model.AC,
                    HC          = model.HC,
                    DC          = model.DC,
                    Durability  = model.Durability,
                    Generation  = model.Generation
                };

                if (model.Image?.Length > 0)
                {
                    var dirPath = Path.Combine(_hostingEnvironment.WebRootPath, _appOptions.ItemImagePath);
                    var dirInfo = new DirectoryInfo(dirPath);
                    if (dirInfo.Exists != true)
                    {
                        dirInfo.Create();
                    }

                    var fileName     = Path.GetFileName(model.Image.FileName);
                    var fileFullPath = Path.Combine(dirInfo.FullName, fileName);
                    using (var stream = new FileStream(fileFullPath, FileMode.Create))
                    {
                        await model.Image.CopyToAsync(stream);
                    }

                    item.Image = "/" + Path.Combine(_appOptions.ItemImagePath, fileName);
                }

                _context.Add(item);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
Beispiel #24
0
        public IActionResult Post(CreateItemViewModel itemViewModel)
        {
            var item = new Item
            {
                Title       = itemViewModel.Title,
                Description = itemViewModel.Description
            };

            try
            {
                itemRepository.Add(item);
                return(Ok(new { Message = "Item successfully created." }));
            }
            catch (Exception e)
            {
                return(StatusCode(500, e.Message));
            }
        }
        public IActionResult CreateItem()
        {
            var manufacturers = _manufacturerRepository.GetManufacturers();
            var categories    = _categoryRepository.GetCategories();



            var manufacturerList = new ManufacturersList(manufacturers.ToList());
            var categoryList     = new CategoriesList(categories.ToList());

            var createUItem = new CreateItemViewModel
            {
                ManufacturerSelectListItems = manufacturerList.GetManufacturersList(),
                CategorySelectListItems     = categoryList.GetCategoriesList()
            };

            return(View(createUItem));
        }
Beispiel #26
0
        public async Task <ActionResult> CreateItem(int Id)
        {
            Menu menu = await DbManager.Menus.FirstOrDefaultAsync(m => m.MenuId == Id);

            if (menu != null)
            {
                CreateItemViewModel itemViewModel = new CreateItemViewModel()
                {
                    IsAvailable = true,
                    MenuId      = Id
                };
                return(View(itemViewModel));
            }
            else
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
        }
Beispiel #27
0
        // GET: Items/Create
        public async Task <IActionResult> CreateItem(int?WishListId, int?GiftListId)
        {
            var viewModel = new CreateItemViewModel();

            if (WishListId != null)
            {
                viewModel.WishListId = WishListId;
                viewModel.WishList   = await _context.WishLists.FindAsync(WishListId);
            }

            if (GiftListId != null)
            {
                viewModel.GiftListId = GiftListId;
                viewModel.GiftList   = await _context.GiftLists.FindAsync(GiftListId);
            }

            return(View(viewModel));
        }
        public ActionResult CreateItem(CreateItemViewModel model, IEnumerable<HttpPostedFileBase> files)
        {
            foreach (var file in files)
            {
                if (file != null && file.ContentLength > 0)
                {
                    var image = new Image
                                    {
                                        FileName = Path.GetFileName(file.FileName),
                                        Extension = Path.GetExtension(file.FileName),
                                        ContentType = file.ContentType,
                                        ContentLength = file.ContentLength,
                                    };

                    using (var reader = new BinaryReader(file.InputStream))
                    {
                        image.ImageArray = reader.ReadBytes(file.ContentLength);
                    }

                    model.Images.Add(image);
                }
            }

            if (this.ModelState.IsValid)
            {
                var item = new Item
                {
                    Title = model.Title,
                    Type = model.Type,
                    Author = model.Author,
                    Description = model.Description,
                    Images = model.Images
                };

                this.dataItem.Add(item);
                this.dataItem.Save();

                TempData["Success"] = "You have successfully created new Item";

                return this.RedirectToAction("ListAllItems", "PublicItem", new { area = string.Empty});
            }

            return this.View(model);
        }
Beispiel #29
0
        public async Task <IActionResult> CreateTodo(Guid listId, [FromBody] CreateItemViewModel todo)
        {
            var userEmail = User.FindFirst(c => c.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress").Value;
            var accountId = User.ReadClaimAsGuidValue("urn:codefliptodo:accountid");

            var command = new CreateItem
            {
                AccountId = accountId,
                Email     = userEmail,
                DueDate   = todo.DueDate,
                ListId    = listId,
                Name      = todo.Name,
                Notes     = todo.Notes
            };

            var todoItem = await _mediator.Send(command);

            return(Ok(todoItem));
        }
Beispiel #30
0
        public async Task <IActionResult> Create(CreateItemViewModel viewModel)
        {
            var item = viewModel.Item;

            ModelState.Remove("Item.CreatorId");
            if (ModelState.IsValid)
            {
                var user = await GetCurrentUserAsync();

                item.CreatorId = user.Id;
                item.Purchased = false;
                _context.Items.Add(item);
                await _context.SaveChangesAsync();

                if (viewModel.WishListId != null)
                {
                    var wishListItem = new WishListItem
                    {
                        WishListId = (int)viewModel.WishListId,
                        ItemId     = item.ItemId,
                        Notes      = viewModel.WishListItem.Notes
                    };
                    _context.WishListItems.Add(wishListItem);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Details), "WishLists", new { id = viewModel.WishListId }));
                }
                if (viewModel.GiftListId != null)
                {
                    var giftListItem = new GiftListItem
                    {
                        GiftListId = (int)viewModel.GiftListId,
                        ItemId     = item.ItemId,
                        Notes      = viewModel.GiftListItem.Notes
                    };
                    _context.GiftListItems.Add(giftListItem);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Details), "GiftLists", new { id = viewModel.GiftListId }));
                }
            }
            return(View(viewModel));
        }
        private string ProcessUploadedFile(CreateItemViewModel model)
        {
            string UniqueFileName = null;

            if (!(model.ItemImage == null))
            {
                string imgsFolder = Path.Combine(webHostEnvironment.WebRootPath, "images");
                UniqueFileName = Guid.NewGuid().ToString() + "_" + model.ItemImage.FileName; //class that can create a string of guarenteed unique characters (an unique id)
                string FilePath = Path.Combine(imgsFolder, UniqueFileName);
                using var fileStream = new FileStream(FilePath, FileMode.Create);
                model.ItemImage.CopyTo(fileStream);

                //using (var fileStream = new FileStream(FilePath, FileMode.Create))
                //{
                //    model.ItemImage.CopyTo(fileStream);
                //}
            }

            return(UniqueFileName);
        }
 public void AddItem(CreateItemViewModel viewModel)
 {
     _itemService.Add(new ItemDto{Name=viewModel.Name, Description = viewModel.Description});
 }