예제 #1
0
        public async Task <IActionResult> Create(ItemViewModel item)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var Item = mapper.Map <Item>(item);
                    Item.ImgUrl    = uploadImages.AddImage(item.File);
                    Item.Sorting   = _context.Items.Count() + 1;
                    Item.ShortLink = RandomURL.GetURL();
                    Item.Date      = DateTime.Now.ToShortDateString();
                    if (Item.RatingValues == null)
                    {
                        Item.RatingValues = 0;
                    }
                    if (Item.RatingCount == null)
                    {
                        Item.RatingCount = 0;
                    }

                    if (item.RaitingValue != 0)
                    {
                        Item.RatingCount++;
                        Item.RatingValues += item.RaitingValue;
                    }



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

                    return(RedirectToAction(nameof(Index)));
                }
                ViewData["CityId"]   = new SelectList(_context.Cities, "Id", "Name", item.CityId);
                ViewData["MemberId"] = new SelectList(supliers(), "Id", "FullName", item.MemberId);
                ViewData["UnitId"]   = new SelectList(units(), "Id", "Name");


                return(View(item));
            }
            catch
            {
                return(RedirectToAction(nameof(Index)));
            }
        }
예제 #2
0
        public async Task <IActionResult> Create(CategoryViewModel category)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    Category Category = mapper.Map <Category>(category);
                    Category.ImgUrl = uploadImages.AddImage(category.File);

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

                    return(RedirectToAction(nameof(Index)));
                }
                return(View(category));
            }
            catch
            {
                return(RedirectToAction(nameof(Index)));
            }
        }
예제 #3
0
        public async Task <IActionResult> Create(MemberViewModel member)
        {
            try
            {
                member.ItemsCount = 0;
                if (ModelState.IsValid)
                {
                    var Member = mapper.Map <Member>(member);
                    Member.ImgUrl         = uploadImages.AddImage(member.File);
                    Member.ActivationCode = RandomURL.GetURL();
                    _context.Add(Member);
                    var created = await _context.SaveChangesAsync();

                    if (created >= 0)
                    {
                        //add Customer to role
                        var supplier = _context.Members.ToList().LastOrDefault();
                        var role     = _context.Roless.FirstOrDefault(r => r.Name == "Customer");
                        if (role != null && supplier != null)
                        {
                            MemberRole SupplierRole = new MemberRole();
                            SupplierRole.MemberId = supplier.Id;
                            SupplierRole.RoleId   = role.Id;
                            _context.MemberRoles.Add(SupplierRole);
                            _context.SaveChanges();
                        }
                    }



                    return(RedirectToAction(nameof(Index)));
                }
                ViewData["CityId"] = new SelectList(_context.Cities, "Id", "Name", member.CityId);
                return(View(member));
            }
            catch
            {
                return(RedirectToAction(nameof(Index)));
            }
        }