public IActionResult OnPost()
        {
            if (ModelState.IsValid)
            {
                if (Request.Form["scrap"].Count() == 1)
                {
                    Purchase.ScrapDate        = DateTime.Today;
                    Purchase.ScrapValue       = Purchase.CurrentInventory * Purchase.LandedCostPerUnit;
                    Purchase.CurrentInventory = 0;
                }

                Purchase.RawMaterial = RawMaterials.First(e => e.RawMaterialItemId == Int32.Parse(ChosenRawMaterialId));
                Purchase.Currency    = Currencies.First(e => e.CurrencyName == ChosenCurrency);

                if (_db.AddPurchase(Purchase))
                {
                    SuccessMessage = Editing ? "Purchase updated succesfully." : "Purchase created succesfully.";
                }
                else
                {
                    ErrorMessage = Editing ? "Purchase updated unsuccesfully." : "Purchase created unsuccesfully. " + "Please try again or contact sysadmin.";
                }
                return(Page());
            }
            ErrorMessage = "Purchase info not valid. Please try again.";
            return(Page());
        }
        private async void OnDeleteClick(WpfRawMaterial wpfRawMaterial)
        {
            if (wpfRawMaterial == null)
            {
                return;
            }

            var    rawMaterialToDb = RestproMapper.MapWpfRawMaterialToRawMaterial(wpfRawMaterial);
            string errorMessage    = null;

            try
            {
                RawMaterials.Remove(wpfRawMaterial);
                if (wpfRawMaterial.Id != 0)
                {
                    _unitOfWork.RawMaterials.FakeDelete(rawMaterialToDb);
                }
                await dialogCoordinator.ShowMessageAsync(this, "Success", "Raw Material Deleted Successfully. Good Bye :(");
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                errorMessage = e.Message;
            }

            if (errorMessage == null)
            {
                return;
            }

            await dialogCoordinator
            .ShowMessageAsync(this, "Error"
                              , "Fatal Error Occured. You're Screwed!\n" +
                              errorMessage);
        }
Ejemplo n.º 3
0
        public RawMaterials Create(EnsolStockMovement rawMaterials, string orderType, string orderNumber)
        {
            if (rawMaterials == null)
            {
                throw new ArgumentNullException("role");
            }

            RawMaterials db = new RawMaterials();
            db.IdCompany = rawMaterials.IdCompany;
            db.ProcessOrder = rawMaterials.ProcessOrder;
            db.Code = rawMaterials.Code;
            db.Description = rawMaterials.Description;
            db.Batch = rawMaterials.Batch;
            db.Quantity = rawMaterials.Quantity;
            db.ECAStorageCode = rawMaterials.ECAStorageCode;
            db.ICAStorageCode = rawMaterials.ICAStorageCode;
            db.Message = rawMaterials.Message;
            db.ECA = rawMaterials.ECA;
            db.OrderType = orderType;
            db.OrderNumber = orderNumber;
            db.Stamp = DateTime.Now;

            //TODO: buscar forma correcta de vincular errores en la capa de datos hacia la capa de distribución.
            if (Exists(db.ProcessOrder.Value))
            {
                return null;
            }

            context.RawMaterials.Add(db);
            context.SaveChanges();

            return db;
        }
        public async Task <IActionResult> Edit(short id, [Bind("IdRawMaterials,Names,UnitOfMeasure,Summ,Quantity")] RawMaterials rawMaterials)
        {
            if (id != rawMaterials.IdRawMaterials)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    await Task.Run(() => rawMaterialsrepo.Update(rawMaterials));
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RawMaterialsExists(rawMaterials.IdRawMaterials))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["UnitOfMeasure"] = new SelectList(unitsrepo.GetList(), "IdUnitOfmeasure", "Names", rawMaterials.UnitOfMeasure);
            return(View(rawMaterials));
        }
        private async void OnSave()
        {
            var rawMaterialsToDb = RestproMapper
                                   .MapWpfRawMaterialLIstToRawMaterialList(RawMaterials.ToList());
            string errorMessage = null;

            try
            {
                _unitOfWork.RawMaterials.AddOrUpdateRawMaterials(rawMaterialsToDb);
                LoadRawMaterials();
                await dialogCoordinator.ShowMessageAsync(this, "Success", "Items Saved Successfully. You Rock!");
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
                errorMessage = e.Message;
            }

            if (errorMessage == null)
            {
                return;
            }

            await dialogCoordinator
            .ShowMessageAsync(this, "Error"
                              , "Fatal Error Occured. You're Screwed!\n" +
                              errorMessage);
        }
Ejemplo n.º 6
0
        public ActionResult DeleteConfirmed(int id)
        {
            RawMaterials rawmaterials = db.RawMaterials.Find(id);

            db.RawMaterials.Remove(rawmaterials);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 7
0
 public ActionResult Edit([Bind(Include = "idMaterial,NameMaterial")] RawMaterials rawMaterials)
 {
     if (ModelState.IsValid)
     {
         db.Entry(rawMaterials).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(rawMaterials));
 }
Ejemplo n.º 8
0
        public void Delete(int id)
        {
            var RawMaterials = new RawMaterials
            {
                RawMaterialId = id
            };

            unitOfWork.RawMaterialsRepository.Delete(RawMaterials);
            unitOfWork.Save();
        }
Ejemplo n.º 9
0
        //
        // GET: /RawMaterials/Details/5

        public ActionResult Details(int id = 0)
        {
            RawMaterials rawmaterials = db.RawMaterials.Find(id);

            if (rawmaterials == null)
            {
                return(HttpNotFound());
            }
            return(View(rawmaterials));
        }
Ejemplo n.º 10
0
 public ActionResult Edit(RawMaterials rawmaterials)
 {
     if (ModelState.IsValid)
     {
         db.Entry(rawmaterials).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.UserId = new SelectList(db.UserProfiles, "UserId", "UserName", rawmaterials.UserId);
     return(View(rawmaterials));
 }
Ejemplo n.º 11
0
        //
        // GET: /RawMaterials/Edit/5

        public ActionResult Edit(int id = 0)
        {
            RawMaterials rawmaterials = db.RawMaterials.Find(id);

            if (rawmaterials == null)
            {
                return(HttpNotFound());
            }
            ViewBag.UserId = new SelectList(db.UserProfiles, "UserId", "UserName", rawmaterials.UserId);
            return(View(rawmaterials));
        }
Ejemplo n.º 12
0
        public ActionResult Create([Bind(Include = "idMaterial,NameMaterial")] RawMaterials rawMaterials)
        {
            if (ModelState.IsValid)
            {
                db.RawMaterials.Add(rawMaterials);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(rawMaterials));
        }
        public async Task <IActionResult> Create([Bind("IdRawMaterials,Names,UnitOfMeasure,Summ,Quantity")] RawMaterials rawMaterials)
        {
            if (ModelState.IsValid)
            {
                await Task.Run(() => rawMaterialsrepo.Create(rawMaterials));

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["UnitOfMeasure"] = new SelectList(unitsrepo.GetList(), "IdUnitOfmeasure", "Names", rawMaterials.UnitOfMeasure);
            return(View(rawMaterials));
        }
Ejemplo n.º 14
0
 public ActionResult Edit([Bind(Include = "Id,Name,Category,Description,Width,length,Count,Cost")] RawMaterials rawmaterials)
 {
     if (ModelState.IsValid)
     {
         db.Entry(rawmaterials).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.Category = new SelectList(db.CatRawMaterials, "Id", "Name", rawmaterials.Category);
     return(View(rawmaterials));
 }
Ejemplo n.º 15
0
        public void Update(RawMaterialsViewModel RawMaterialsViewModel)
        {
            var RawMaterials = new RawMaterials
            {
                RawMaterialId = RawMaterialsViewModel.RawMaterialId,
                ItemId        = RawMaterialsViewModel.ItemId,
                ItemElementId = RawMaterialsViewModel.ItemElementId
            };

            unitOfWork.RawMaterialsRepository.Update(RawMaterials);
            unitOfWork.Save();
        }
Ejemplo n.º 16
0
        public ActionResult Create(RawMaterials rawmaterials)
        {
            if (ModelState.IsValid)
            {
                db.RawMaterials.Add(rawmaterials);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.UserId = new SelectList(db.UserProfiles, "UserId", "UserName", rawmaterials.UserId);
            return(View(rawmaterials));
        }
Ejemplo n.º 17
0
        // GET: /RawMaterials/Delete/5
        public ActionResult Delete(short?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            RawMaterials rawmaterials = db.RawMaterials.Find(id);

            if (rawmaterials == null)
            {
                return(HttpNotFound());
            }
            return(View(rawmaterials));
        }
Ejemplo n.º 18
0
        // GET: /RawMaterials/Edit/5
        public ActionResult Edit(short?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            RawMaterials rawmaterials = db.RawMaterials.Find(id);

            if (rawmaterials == null)
            {
                return(HttpNotFound());
            }
            ViewBag.Category = new SelectList(db.CatRawMaterials, "Id", "Name", rawmaterials.Category);
            return(View(rawmaterials));
        }
Ejemplo n.º 19
0
        public void Create(RawMaterialsViewModel RawMaterialsViewModel)
        {
            //string strmsg = "";
            int x = RawMaterialsViewModel.ItemElementId1.Count();

            for (int i = 0; i < x; i++)
            {
                //var arrayItemId = RawMaterialsViewModel.ItemId1[i];
                var arrayItemElementId = RawMaterialsViewModel.ItemElementId1[i];



                var RawMaterials = new RawMaterials
                {
                    ItemId        = RawMaterialsViewModel.ItemId1,
                    ItemElementId = arrayItemElementId
                };

                unitOfWork.RawMaterialsRepository.Insert(RawMaterials);
                unitOfWork.Save();
            }
        }
 private bool CanSave()
 {
     return(RawMaterials == null || RawMaterials.All(a => !a.HasErrors));
 }