예제 #1
0
 public CreateItemInputModel LoadItem(int ID)
 {
     try
     {
         var obj = cnn.Items.Find(ID);
         CreateItemInputModel Item = new CreateItemInputModel();
         Item.ID            = obj.ID;
         Item.Code          = obj.Code;
         Item.Name          = obj.Name;
         Item.Point         = obj.Point.Value;
         Item.Status        = obj.Status;
         Item.Price         = obj.Price.ToString();
         Item.AgentPrice    = obj.AgentPrice.ToString();
         Item.DiscountPrice = obj.DiscountPrice.ToString();
         Item.ImageUrl      = obj.ImageUrl;
         Item.Description   = obj.Description;
         Item.Brand         = obj.Brand;
         Item.Warranty      = obj.Warranty;
         Item.MadeIn        = obj.MadeIn;
         return(Item);
     }
     catch (Exception ex)
     {
         ex.ToString();
         return(new CreateItemInputModel());
     }
 }
예제 #2
0
 public int CreateItem(CreateItemInputModel Input)
 {
     try
     {
         if (CheckExistingItem(Input.Code))
         {
             return(SystemParam.EXISTING);
         }
         Item item = new Item();
         item.CateID        = Input.CategoryID;
         item.Code          = Input.Code.Trim();
         item.Name          = Input.Name.Trim();
         item.Point         = Convert.ToInt32((Input.Pointstr).ToString().Replace(",", ""));
         item.Brand         = Input.Brand.Trim();
         item.MadeIn        = Input.MadeIn.Trim();
         item.Warranty      = Input.Warranty.Trim();
         item.Price         = Convert.ToInt32((Input.Price).ToString().Replace(",", ""));
         item.AgentPrice    = Convert.ToInt32((Input.AgentPrice).ToString().Replace(",", ""));
         item.DiscountPrice = Convert.ToInt32((Input.DiscountPrice).ToString().Replace(",", ""));
         item.ImageUrl      = Input.ImageUrl.ToString();
         item.Description   = Input.Description.Trim();
         item.Status        = SystemParam.ACTIVE;
         item.CreateDate    = DateTime.Today;
         item.IsActive      = SystemParam.ACTIVE;
         cnn.Items.Add(item);
         cnn.SaveChanges();
         return(SystemParam.RETURN_TRUE);
     }
     catch (Exception ex)
     {
         ex.ToString();
         return(SystemParam.RETURN_FALSE);
     }
 }
예제 #3
0
        public IActionResult Create(CreateItemInputModel model)
        {
            CreateItemsDto item = this.mapper.Map <CreateItemsDto>(model);

            this.itemService.Create(item);

            return(RedirectToAction("All"));
        }
예제 #4
0
        public IActionResult Create(CreateItemInputModel model)
        {
            var item = this.mapper.Map <Item>(model);

            this.context.Items.Add(item);

            this.context.SaveChanges();
            return(this.RedirectToAction("All"));
        }
        public IActionResult Create()
        {
            var viewModel = new CreateItemInputModel
            {
                Categories = this.categoriesService.GetAllAsKeyValuePairs(),
            };

            return(this.View(viewModel));
        }
        public IActionResult Create(CreateItemInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Error", "Home"));
            }
            Item item = mapper.Map <Item>(model);

            context.Items.Add(item);
            context.SaveChanges();
            return(RedirectToAction("All", "Items"));
        }
예제 #7
0
 public int SaveEditItem(CreateItemInputModel Input)
 {
     try
     {
         return(itemBusiness.SaveEditItem(Input));
     }
     catch (Exception ex)
     {
         ex.ToString();
         return(SystemParam.ERROR);
     }
 }
예제 #8
0
        public IActionResult Create(CreateItemInputModel model)
        {
            if (!ModelState.IsValid)
            {
                //
            }

            var item = this.mapper.Map <Item>(model);

            this.context.Items.Add(item);
            this.context.SaveChanges();

            return(RedirectToAction("All", "Items"));
        }
예제 #9
0
        public IActionResult Create(CreateItemInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(this.RedirectToAction("Error", "Home"));
            }

            var itemToAdd = this.mapper.Map <Item>(model);

            this.context.Add(itemToAdd);
            this.context.SaveChanges();

            return(this.Redirect("/Items/All"));
        }
예제 #10
0
        public IActionResult Create(CreateItemInputModel model)
        {
            if (ModelState.IsValid == false)
            {
                return(this.RedirectToAction("Error", "Home"));
            }

            var item = this.mapper.Map <Item>(model);

            this.context.Items.Add(item);

            this.context.SaveChanges();

            return(this.RedirectToAction("All"));
        }
예제 #11
0
        public ItemStartUp()
        {
            var config = new MapperConfiguration(cfg => cfg.AddProfile <FastFoodProfile>());

            _mapper = new Mapper(config);

            _context = new FastFoodContext();

            _viewModel = new CreateItemInputModel
            {
                Name         = "Power Supply",
                CategoryName = "Electronics",
                Price        = 37.77M
            };
        }
예제 #12
0
        public IActionResult Create(CreateItemInputModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.RedirectToAction("Error", "Home"));
            }

            var category = this.mapper.Map <Item>(model);

            this.context.Add(category);

            this.context.SaveChanges();

            return(this.RedirectToAction("All", "Items"));
        }
예제 #13
0
        public IActionResult Create(CreateItemInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Error", "Home"));
            }

            Item     item     = this.mapper.Map <Item>(model);
            Category category = this.context.Categories.FirstOrDefault(c => c.Name == model.CategoryName);

            item.CategoryId = category.Id;
            this.context.Items.Add(item);
            this.context.SaveChanges();

            return(this.RedirectToAction("All", "Items"));
        }
예제 #14
0
        public IActionResult Create(CreateItemInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Error", "Home"));
            }

            var item = this.mapper.Map <Item>(model);

            item.Category = this.context.Categories
                            .SingleOrDefault(c => c.Id == item.CategoryId);

            this.context.Items.Add(item);

            this.context.SaveChanges();

            return(this.RedirectToAction("All", "Items"));
        }
예제 #15
0
        public IActionResult Create(CreateItemInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Error", "Home"));
            }

            if (this.context.Items.Any(i => i.Name == model.Name))
            {
                return(RedirectToAction("Error", "Home"));
            }

            var item = this.mapper.Map <Item>(model);

            this.context.Items.Add(item);

            this.context.SaveChanges();

            return(this.RedirectToAction("All", "Items"));
        }
        public async Task <IActionResult> Create(CreateItemInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(input));
            }

            var user = await this.userManager.GetUserAsync(this.User);

            try
            {
                await this.itemsService.CreateAsync(input, user.Id, $"{this.environment.WebRootPath}/images");
            }
            catch (Exception ex)
            {
                this.ModelState.AddModelError(string.Empty, ex.Message);
                return(this.View(input));
            }

            return(this.Redirect("/Marketplace/All"));
        }
예제 #17
0
        public IActionResult Create(CreateItemInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Error", "Home"));
            }

            var item = mapper.Map <Item>(model);

            var category = context.Categories.FirstOrDefault(x => x.Name == model.CategoryName);

            if (category != null)
            {
                item.CategoryId = category.Id;
            }

            context.Items.Add(item);
            context.SaveChanges();

            return(RedirectToAction("All", "Items"));
        }
예제 #18
0
 public int SaveEditItem(CreateItemInputModel Input)
 {
     try
     {
         var pointInt = Convert.ToInt32((Input.Pointstr).ToString().Replace(",", ""));
         var obj      = cnn.Items.Find(Input.ID);
         if (pointInt != obj.Point)
         {
             NotifyBusiness notify  = new NotifyBusiness();
             List <int>     idAgent = (from c in cnn.Customers
                                       where c.IsActive.Equals(SystemParam.ACTIVE) && c.Role.Equals(SystemParam.ROLE_ADMIN) && c.DeviceID.Length >= 15
                                       select c.ID).ToList();
             foreach (var id in idAgent)
             {
                 string contennotify = "Chiết khấu cho sản phẩm " + obj.Name + " được thay đổi là " + pointInt + " điểm, được áp dụng từ thời điểm hiện tại cho đại lý";
                 notify.CreateNoti(id, SystemParam.CHANGE_MINUS_POINT_ITEM, 0, contennotify, contennotify, null);
             }
         }
         obj.Code          = Input.Code;
         obj.Name          = Input.Name.Trim();
         obj.Point         = pointInt;
         obj.Price         = Convert.ToInt32((Input.Price).ToString().Replace(",", ""));
         obj.AgentPrice    = Convert.ToInt32((Input.AgentPrice).ToString().Replace(",", ""));
         obj.DiscountPrice = Convert.ToInt32((Input.DiscountPrice).ToString().Replace(",", ""));
         obj.ImageUrl      = Input.ImageUrl;
         obj.Description   = Input.Description.Trim();
         obj.Brand         = Input.Brand.Trim();
         obj.Warranty      = Input.Warranty.Trim();
         obj.MadeIn        = Input.MadeIn.Trim();
         obj.Status        = Input.Status;
         cnn.SaveChanges();
         return(SystemParam.RETURN_TRUE);
     }
     catch (Exception ex)
     {
         ex.ToString();
         return(SystemParam.RETURN_FALSE);
     }
 }
예제 #19
0
        public async Task CreateAsync(CreateItemInputModel input, string userId, string imagePath)
        {
            var item = new ItemForSale()
            {
                Name        = input.Name,
                Description = input.Description,
                Price       = input.Price,
                UserId      = userId,
            };

            var category = this.categoryRepository.All().FirstOrDefault(x => x.Id == input.CategoryId);

            item.Category = category;

            Directory.CreateDirectory($"{imagePath}/itemsForSale/");
            foreach (var image in input.Images)
            {
                var extension = Path.GetExtension(image.FileName).TrimStart('.');
                if (!this.allowedExtensions.Any(x => extension.EndsWith(x)))
                {
                    throw new Exception($"Invalid image extension {extension}");
                }

                var dbImage = new Image
                {
                    Extension = extension,
                    UserId    = userId,
                };
                item.Images.Add(dbImage);

                var physicalPath = $"{imagePath}/itemsForSale/{dbImage.Id}.{extension}";
                using Stream fileStream = new FileStream(physicalPath, FileMode.Create);
                await image.CopyToAsync(fileStream);
            }

            await this.itemsRepository.AddAsync(item);

            await this.itemsRepository.SaveChangesAsync();
        }
예제 #20
0
 public IActionResult Create(CreateItemInputModel model)
 {
     throw new NotImplementedException();
 }