Пример #1
0
        public async Task <IActionResult> SupplyHistory()
        {
            List <SupplyHeader> headers = await _context.SupplyHeaders.ToListAsync();

            List <SupplyViewModel> supplies = new List <SupplyViewModel>()
            {
            };

            foreach (var sh in headers)
            {
                SupplyViewModel supply = new SupplyViewModel
                {
                    supplyHeader  = sh,
                    supplyDetails = await _context.SupplyDetails.Where(x => x.SupplyHeaderId == sh.Id).ToListAsync()
                };
                supplies.Add(supply);
            }

            await _context.Bikes.ToListAsync();

            await _context.Models.ToListAsync();

            await _context.ModelColours.ToListAsync();

            await _context.FrameSizes.ToListAsync();

            await _context.Colours.ToListAsync();

            await _context.Users.ToListAsync();

            return(View(supplies));
        }
        public async Task <IActionResult> Edit(int Id)
        {
            var Supply = await _supplyRepository.GetByIdAsync(Id);

            var supplyViewModel = new SupplyViewModel();

            supplyViewModel.Id             = Supply.Id;
            supplyViewModel.Name           = Supply.Name;
            supplyViewModel.Contact_person = Supply.Contact_person;
            supplyViewModel.Title          = Supply.TitleId;
            supplyViewModel.Address        = Supply.Address;
            supplyViewModel.Postcode       = Supply.Postcode;
            supplyViewModel.Telphone       = Supply.Telphone;
            supplyViewModel.Fax            = Supply.Fax;

            var titles = await _titleRepository.ListAsync();

            //取得職稱資料後送到前端
            ViewBag.Titles = titles.Select(r => new SelectListItem
            {
                Text  = r.Name,
                Value = r.Id.ToString()
            });

            return(View(supplyViewModel));
        }
        public ActionResult ConfirmDelete(int id)
        {
            Supply          supply     = db.Supplies.Find(id);
            var             material   = db.Materials.Where(p => p.Id == supply.MaterialId).First();
            SupplyViewModel supplyView = new SupplyViewModel
            {
                Supplier          = supply.Supplier,
                NameMaterial      = material.Name,
                QuantityMaterials = supply.Quantity,
                Price             = supply.Price,
                Delivery_date     = supply.Delivery_date
            };
            SuppliesVeiwModel veiwModel = new SuppliesVeiwModel
            {
                SupplyViewModel = supplyView
            };

            if (supply == null)
            {
                return(View("NotFound"));
            }
            else
            {
                return(View(veiwModel));
            }
        }
Пример #4
0
        // GET: Supply/Create
        public ActionResult Create(int id)
        {
            SupplyViewModel viewModel = new SupplyViewModel();

            try {
                int userid = 0;
                if (TempData["UserId"] != null)
                {
                    userid = (int)TempData["UserId"];
                }
                else
                {
                    userid             = id;
                    TempData["UserId"] = userid;
                }

                var vehicles = vehicleService.FindByUser(userid);
                viewModel.vehicles = vehicles;
                viewModel.userid   = userid;
            }
            catch (Exception ex)
            {
            }
            return(View(viewModel));
        }
Пример #5
0
        // GET: Supply
        public ActionResult Index(int id, List <Supply> supplies)
        {
            SupplyViewModel viewModel = new SupplyViewModel();

            try {
                int userid = 0;

                if (TempData["UserId"] != null)
                {
                    userid = (int)TempData["UserId"];
                }
                else
                {
                    userid = id;
                }


                TempData["UserId"] = userid;
                viewModel.userid   = userid;
                viewModel.supplies = supplyService.FindByUserId(userid);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(View(viewModel));
        }
Пример #6
0
 public async Task <OperationStatus> AddSupply(SupplyViewModel supply)
 {
     return(await unsafeSupplyService.Add(new Supply
     {
         ProviderId = supply.Provider.Id,
         EmployeeId = (await safeEmployeeService.GetEmployeeByName(supply.Employee.Name, true)).Id,
         ItemId = supply.Item.Id,
         StatusId = (await safeItemStatusService.GetStatus(Status.Processing)).Id,
         Count = supply.Count,
         DateTime = DateTime.Now
     }));
 }
Пример #7
0
        public async Task <IActionResult> Edit(int Id)
        {
            var Deliver = await _deliverRepository.GetByIdAsync(Id);

            var deliverViewModel = new SupplyViewModel();

            deliverViewModel.Id             = Deliver.Id;
            deliverViewModel.Name           = Deliver.Name;
            deliverViewModel.Contact_person = Deliver.Contact_person;
            deliverViewModel.Telphone       = Deliver.Telphone;

            return(View(deliverViewModel));
        }
Пример #8
0
        public async Task AddSupply([FromBody] SupplyViewModel value)
        {
            if (!ModelState.IsValid)
            {
                BadRequest();
            }

            var status = await unsafeOperationService.AddSupply(value);

            if (status == WareHouse.Data.Repository.OperationStatus.Error)
            {
                HttpContext.Response.StatusCode = 500;
            }
        }
Пример #9
0
 private void Change_Click(object sender, RoutedEventArgs e)
 {
     if (DataGridView.SelectedIndex != -1)
     {
         var             window    = Container.Resolve <CreateSupplyWindow>();
         SupplyViewModel garniture = (SupplyViewModel)DataGridView.SelectedCells[0].Item;
         window.Id = Convert.ToInt32(garniture.Id);
         window.ShowDialog();
         if (window.DialogResult == true)
         {
             LoadData();
         }
     }
 }
Пример #10
0
        public ActionResult Create(SupplyViewModel viewModel)
        {
            try
            {
                Supply supply = new Supply();
                int    userid = 0;

                if (TempData["UserId"] != null)
                {
                    userid = (int)TempData["UserId"];
                }
                else
                {
                    userid             = viewModel.userid;
                    TempData["UserId"] = userid;
                }


                supply.datasupply  = viewModel.datasupply;
                supply.fueltype    = viewModel.fueltype;
                supply.kmsupply    = viewModel.kmsupply;
                supply.quantity    = viewModel.quantity;
                supply.userid      = userid;
                supply.value       = viewModel.value;
                supply.vehicleid   = viewModel.vehicleid;
                supply.companyname = viewModel.companyname;

                bool result   = supplyService.Create(supply);
                var  vehicles = vehicleService.FindByUser(userid);
                viewModel.vehicles = vehicles;

                if (result)
                {
                    viewModel.message = "Cadastro Realizado com sucesso!";
                }
                else
                {
                    viewModel.message = "Falha no cadastro de abastecimento";
                }
            }
            catch
            {
            }
            return(View(viewModel));
        }
        public async Task <IActionResult> Add(SupplyViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("Add"));
            }

            await _supplyRepository.AddAsync(new Supply
            {
                Name           = model.Name,
                Contact_person = model.Contact_person,
                TitleId        = model.Title,
                Address        = model.Address,
                Postcode       = model.Postcode,
                Telphone       = model.Telphone,
                Fax            = model.Fax,
                Creadedate     = DateTime.Now
            });

            return(RedirectToAction("Index"));
        }
Пример #12
0
        // GET: Supply/Report/5
        public ActionResult Report(SupplyViewModel viewModel)
        {
            int userid = 0;

            if (TempData["UserId"] != null)
            {
                userid = (int)TempData["UserId"];
            }
            else
            {
                userid = viewModel.userid;
            }

            var result = supplyService.SearchLitersMonth(userid);

            viewModel.supplies = result;
            viewModel.userid   = userid;


            return(RedirectToAction("Index", new { id = viewModel.reporttype, supplies = viewModel.supplies }));
        }
Пример #13
0
        public ActionResult Create(SupplyViewModel vm)
        {
            try
            {
                var UserId = User.Identity.GetUserId();

                Supply supply = new Supply();
                supply.UserId     = UserId;
                supply.SupplierId = vm.SupplierId;
                supply.SupplyDate = DateTime.Today;

                Db.Supplies.Add(supply);
                Db.SaveChanges();

                int SupplyId = supply.Id;

                foreach (var item in vm.Details)
                {
                    SupplyDetail detail = new SupplyDetail();
                    detail.ProductId     = item.ProductId;
                    detail.PurchasePrice = item.Price;
                    detail.Quantity      = item.Quantity;
                    detail.SupplyId      = SupplyId;

                    var ProductInDb = Db.Products.Find(detail.ProductId);

                    ProductInDb.Quantity += detail.Quantity;

                    Db.SupplyDetails.Add(detail);
                }

                Db.SaveChanges();
                return(RedirectToAction("Details", new { id = SupplyId }));
            }
            catch
            {
                ViewBag.ErrorMessage = "Error occured while adding supply";
                return(View("Error"));
            }
        }
        public async Task <IActionResult> Edit(SupplyViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            await _supplyRepository.ModifiedAsync(
                new Supply
            {
                Id             = model.Id,
                Name           = model.Name,
                Contact_person = model.Contact_person,
                TitleId        = model.Title,
                Address        = model.Telphone,
                Postcode       = model.Postcode,
                Telphone       = model.Telphone,
                Fax            = model.Fax,
                Creadedate     = model.Creadedate
            });

            return(RedirectToAction("Index"));
        }
Пример #15
0
        private void Delete_Click(object sender, RoutedEventArgs e)
        {
            if (DataGridView.SelectedIndex != -1)
            {
                MessageBoxResult result = MessageBox.Show("Удалить запись", "Вопрос", MessageBoxButton.YesNo, MessageBoxImage.Question);

                if (result == MessageBoxResult.Yes)
                {
                    SupplyViewModel material = (SupplyViewModel)DataGridView.SelectedCells[0].Item;
                    int             id       = Convert.ToInt32(material.Id);
                    try
                    {
                        _logic.Delete(new SupplyBindingModel {
                            Id = id
                        });
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                    LoadData();
                }
            }
        }
Пример #16
0
        public IActionResult SupplyInventory(string sortOrder, string searchString)
        {
            SupplyViewModel  model    = new SupplyViewModel();
            List <SupplyObj> supplies = new List <SupplyObj>();

            foreach (var item in _context.Fabric)
            {
                SupplyObj supply = new SupplyObj();
                supply.Id       = item.Id;
                supply.Title    = item.Title;
                supply.Quantity = item.Quantity;
                supply.Type     = "Fabrics";
                supply.Measure  = "yds";
                supplies.Add(supply);
            }


            foreach (var item in _context.Label)
            {
                SupplyObj supply = new SupplyObj();
                supply.Id       = item.Id;
                supply.Title    = item.Title;
                supply.Quantity = item.Quantity;
                supply.Type     = "Labels";
                supply.Measure  = "units";
                supplies.Add(supply);
            }


            foreach (var item in _context.Tag)
            {
                SupplyObj supply = new SupplyObj();
                supply.Id       = item.Id;
                supply.Title    = item.Title;
                supply.Quantity = item.Quantity;
                supply.Type     = "Tags";
                supply.Measure  = "units";
                supplies.Add(supply);
            }


            foreach (var item in _context.Notion)
            {
                SupplyObj supply = new SupplyObj();
                supply.Id       = item.Id;
                supply.Title    = item.Title;
                supply.Quantity = item.Quantity;
                supply.Type     = "Notions";
                supply.Measure  = "units";
                supplies.Add(supply);
            }

            if (!String.IsNullOrEmpty(searchString))
            {
                var temp = supplies.Where(s => s.Title != null && s.Type != null);
                supplies = temp.Where(s => s.Title.ToUpper().Contains(searchString.ToUpper()) ||
                                      s.Type.ToUpper().Contains(searchString.ToUpper())).ToList();
            }

            ViewData["NameSortParm"]  = String.IsNullOrEmpty(sortOrder) ? "Title_desc" : "";
            ViewData["TypeSortParm"]  = sortOrder == "Type" ? "Type_desc" : "Type";
            ViewData["QuantSortParm"] = sortOrder == "Quantity" ? "Quant_desc" : "Quantity";
            switch (sortOrder)
            {
            case "Type":
                supplies = supplies.OrderByDescending(s => s.Type).ToList();
                break;

            case "Type_desc":
                supplies = supplies.OrderBy(s => s.Type).ToList();
                break;

            case "Quantity":
                supplies = supplies.OrderBy(s => s.Quantity).ToList();
                break;

            case "Quant_desc":
                supplies = supplies.OrderByDescending(s => s.Quantity).ToList();
                break;

            case "Title":
                supplies = supplies.OrderBy(s => s.Title).ToList();
                break;

            case "Title_desc":
                supplies = supplies.OrderByDescending(s => s.Title).ToList();
                break;

            default:
                supplies = supplies.OrderBy(s => s.Type).ToList();
                break;
            }
            model.Supplies = supplies;

            return(View(model));
        }