public async Task <IActionResult> Edit(int?productId, int?recepieId,
                                               [Bind("RecepieId,ProductId,Quantity")] RecProd recProd)
        {
            if (recepieId != recProd.RecepieId || productId != recProd.ProductId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(recProd);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RecProdExists(recProd.RecepieId))
                    {
                        ModelState.AddModelError("",
                                                 "Рецептата не може да бъде намерена.");
                    }
                    else
                    {
                        ModelState.AddModelError("",
                                                 "Номерът вече съществува, моля въведете друг.");
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProductIds"] = new SelectList(_context.Products, "ProductID", "ProductName", recProd.ProductId);
            ViewData["RecepieIds"] = new SelectList(_context.Recepies, "RecepieID", "Description", recProd.RecepieId);
            return(View(recProd));
        }
Exemplo n.º 2
0
        public bool Delete(RecProd item, Session session = null)
        {
            //LoggerFactory.CreateLog().Start();
            var committed = 0;

            try
            {
                //if (session != null)
                //    _repositoryRecProd.UnitOfWork.SetConnectionDb(session.ConnectionString);

                if (item == null)
                {
                    throw new ArgumentNullException("item");
                }

                // Domain Services?
                //_repositoryRecProd.Delete(Mapper.Map<Dominio.Entidades.RecProd>(item));
                _repositoryRecProd.Delete(item);
                committed = _unitOfWorkAsync.SaveChanges();
            }
            catch (Exception ex)
            {
                //LoggerFactory.CreateLog().Error(ex);
            }

            //LoggerFactory.CreateLog().Stop();
            return(committed > 0);
        }
        public async Task <IActionResult> AddMore([Bind("RecepieId,ProductId,Quantity")] RecProd recProd)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(recProd);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction("Create", "RecProds", new { recepieid = recProd.RecepieId }));
                }
            }
            catch
            {
                ModelState.AddModelError("",
                                         "Номерът вече съществува, моля въведете друг.");
            }
            ViewData["ProductIds"] = new SelectList(_context.Products, "ProductID", "ProductName", recProd.ProductId);
            ViewData["RecepieIds"] = new SelectList(_context.Recepies, "RecepieID", "Description", recProd.RecepieId);
            return(View(recProd));
        }
        public async Task <IActionResult> Index(RecProd recProd)
        {
            ViewData["Background"] = "\"../images/background2.jpg\"";
            int?SelectedNumber = recProd.Product.ProductID;

            ViewData["ProductIds"] = new SelectList(_context.Products,
                                                    "ProductID", "ProductName", SelectedNumber);
            var d         = _context.Products;
            int productID = SelectedNumber.GetValueOrDefault();
            var recProds  = _context.RecProds
                            .Where(p => !SelectedNumber.HasValue || p.ProductId == productID)
                            .OrderBy(p => p.Quantity)
                            .Include(r => r.Recepie);

            if (SelectedNumber == null || SelectedNumber == 0)
            {
                ViewBag.Selected = "Всички";
                recProds         = _context.RecProds.OrderBy(r => r.Quantity)
                                   .Include(p => p.Recepie);
            }
            return(View(await recProds.ToListAsync()));
        }
Exemplo n.º 5
0
        public bool Update(RecProd item, Session session = null)
        {
            //LoggerFactory.CreateLog().Start();
            var committed = 0;

            try
            {
                //if (session != null)
                //    _repositoryRecProd.UnitOfWork.SetConnectionDb(session.ConnectionString);

                if (item == null)
                {
                    throw new ArgumentNullException("item");
                }

                var validator = EntityValidatorFactory.CreateValidator();
                if (validator.IsValid(item))
                {
                    // Domain Services?
                    //_repositoryRecProd.Update(Mapper.Map<Dominio.Entidades.RecProd>(item));
                    _repositoryRecProd.Update(item);
                    committed = _unitOfWorkAsync.SaveChanges();
                }
                else
                {
                    throw new ApplicationValidationErrorsException(validator.GetInvalidMessages(item));
                }
            }
            catch (Exception ex)
            {
                //LoggerFactory.CreateLog().Error(ex);
            }

            //LoggerFactory.CreateLog().Stop();
            //_repositoryRecProd.Update(entity);
            return(committed > 0);
        }
Exemplo n.º 6
0
 public void ApplyChanges(RecProd entity)
 {
     _repositoryRecProd.ApplyChanges(entity);
 }
Exemplo n.º 7
0
 public RecProdCrudViewModel()
 {
     RecProd = new RecProd();
 }