Beispiel #1
0
 public async Task <IActionResult> Create([Bind("ID,UserName,UserSurname,UserPhone,UserOrganization,FileName,FilePath,Status,MaterialId,AdvTypeId")] Order order, IFormFile file)
 {
     if (ModelState.IsValid)
     {
         if (file != null)
         {
             string path = "/UsersImg/" + file.FileName;
             using (var fileStream = new FileStream(_appEnvironment.WebRootPath + path, FileMode.Create))
             {
                 await file.CopyToAsync(fileStream);
             }
             order.FileName = file.FileName;
             order.FilePath = path;
             var materialPrice = _context.Material.Where(u => u.ID == order.MaterialId).SingleOrDefault().MaterialPrice;
             if (materialPrice == null)
             {
                 materialPrice = 0;
             }
             var advtypePrice = _context.AdvTypes.Where(u => u.ID == order.AdvTypeId).SingleOrDefault().TypePrice;
             if (advtypePrice == null)
             {
                 advtypePrice = 0;
             }
             order.FinalPrice = materialPrice + advtypePrice;
             _context.Add(order);
             _context.SaveChanges();
             ViewData["order-message"] = "Заказ успешно отправлен!";
         }
     }
     return(View(order));
 }
Beispiel #2
0
        public async Task <IActionResult> Create([Bind("ID,MaterialName,MaterialSize,MaterialPrice")] Material material)
        {
            if (ModelState.IsValid)
            {
                _context.Add(material);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(material));
        }
Beispiel #3
0
        public async Task <IActionResult> Create([Bind("ID,TypeName,TypeSize,TypePrice")] AdvType advType)
        {
            if (ModelState.IsValid)
            {
                _context.Add(advType);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(advType));
        }
Beispiel #4
0
        public async Task <IActionResult> Create([Bind("ID,Login,Password")] UserViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new User();
                model.Apply(user);

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

                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }