Esempio n. 1
0
        public async Task <IActionResult> AddIncidentManual([Bind("ID,Iname,Category,Description,Solution,Images,Videos,Date,Status,Count")] Incident incident, List <IFormFile> Images, List <IFormFile> Videos)
        {
            var currentIncidentID = await _context.Incident
                                    .OrderByDescending(m => m.ID)
                                    .FirstOrDefaultAsync();

            var ciID = currentIncidentID.ID + 1;
            var IID  = HttpContext.Session.GetString("ManualID");

            foreach (var item in Images)
            {
                if (item.Length > 0)
                {
                    using (var stream = new MemoryStream())
                    {
                        await item.CopyToAsync(stream);

                        incident.Images = stream.ToArray();
                    }
                }
            }

            foreach (var item in Videos)
            {
                if (item.Length > 0)
                {
                    using (var stream1 = new MemoryStream())
                    {
                        await item.CopyToAsync(stream1);

                        incident.Videos = stream1.ToArray();
                    }
                }
            }

            if (ModelState.IsValid)
            {
                incident.ID = ciID;
                DateTime.Now.Date.ToString("MM / dd / yyyy");
                _context.Add(incident);
                await _context.SaveChangesAsync();


                var incidentss = await _context.IncidentTask
                                 .FirstOrDefaultAsync((m => m.ID.ToString() == HttpContext.Session.GetString("ManualID")));

                if (incidentss != null)
                {
                    incidentss.IID  = ciID;
                    incidentss.Eway = "Auto";
                    _context.Update(incidentss);
                    await _context.SaveChangesAsync();
                }

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

            return(View(incident));
        }
        void IInventoryService.Edit(DTOInventory inventory)
        {
            Address address = _mapper.Map <Address>(inventory.Address);

            _context.Update(address);
            PhoneNumber phone = _mapper.Map <PhoneNumber>(inventory.PhoneNumber);

            _context.Update(phone);
            base.Edit(_mapper.Map <Inventory>(inventory));
        }
Esempio n. 3
0
        public void Edit(DTOSupplier model)
        {
            Address      address  = _mapper.Map <Address>(model.Address);
            PhoneNumber  phone    = model.PhoneNumber;
            EmailAddress email    = model.EmailAddress;
            Supplier     supplier = _mapper.Map <Supplier>(model);

            _context.Update(address);
            _context.Update(phone);
            _context.Update(email);
            _context.Update(supplier);
            _context.SaveChanges();
        }
Esempio n. 4
0
        public void Edit(DTOCustomer model)
        {
            Address      address  = _mapper.Map <Address>(model.Address);
            PhoneNumber  phone    = model.PhoneNumber;
            EmailAddress email    = model.EmailAddress;
            Customer     customer = _mapper.Map <Customer>(model);

            _context.Update(address);
            _context.Update(phone);
            _context.Update(email);
            _context.SaveChanges();

            base.Edit(customer);
        }
Esempio n. 5
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,ProductName,PartNumber,ProductLabel,StartingInventory,InventoryReceived,InventoryShipped,InventoryOnHand,MinimumRequired")] Products products)
        {
            if (id != products.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(products);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProductsExists(products.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(products));
        }
Esempio n. 6
0
        public void Edit(DTOExport model)
        {
            Export export = _mapper.Map <Export>(model);
            List <ExportDetail> newDetails = _mapper.Map <List <ExportDetail> >(model.ExportProductList);
            List <ExportDetail> oldDetails = _context.ExportDetails
                                             .Where(x => x.ExportId == model.Id).ToList();

            _context.Update(export);

            if (newDetails != null && newDetails.Count > 0)
            {
                _context.RemoveRange(oldDetails);
                if (newDetails != null)
                {
                    foreach (var nd in newDetails)
                    {
                        nd.ExportId = export.Id;
                        double productPrice = _context.ProductPrices
                                              .Where(x => x.ProductId == nd.ProductId && !x.IsDeleted)
                                              .FirstOrDefault().Price;
                        nd.Price = nd.Quantity * productPrice - (nd.Quantity * productPrice * nd.Discount / 100);
                    }
                    _context.AddRange(newDetails);
                }
            }
            _context.SaveChanges();
        }
Esempio n. 7
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,SupplierId,ProductId,NumberReceived,PurchaseDate")] Purchases purchases)
        {
            if (id != purchases.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(purchases);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PurchasesExists(purchases.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProductId"]  = new SelectList(_context.Products, "Id", "Id", purchases.ProductId);
            ViewData["SupplierId"] = new SelectList(_context.Suppliers, "Id", "Supplier", purchases.SupplierId);
            return(View(purchases));
        }
Esempio n. 8
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Supplier")] Suppliers suppliers)
        {
            if (id != suppliers.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(suppliers);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SuppliersExists(suppliers.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(suppliers));
        }
Esempio n. 9
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Title,First,Middle,Last,ProductId,NumberShipped,OrderDate")] Orders orders)
        {
            if (id != orders.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(orders);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!OrdersExists(orders.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(orders));
        }
Esempio n. 10
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Username,Pass")] Login login)
        {
            if (id != login.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(login);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!LoginExists(login.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(login));
        }
        public void Edit(DTOEmployee model)
        {
            Address  address  = _mapper.Map <Address>(model.Address);
            Employee employee = _mapper.Map <Employee>(model);

            _context.Update(address);
            _context.SaveChanges();

            EmployeeInventory employeeInventory = _context.EmployeeInventories
                                                  .Where(x => x.EmployeeId == employee.Id && x.EndDate == null)
                                                  .FirstOrDefault();

            if (employeeInventory.InventoryId == null)
            {
                employeeInventory.InventoryId = model.InventoryId;
                if (employeeInventory.InventoryId != null)
                {
                    employeeInventory.HireDate = DateTime.Now;
                }
            }
            else
            {
                if (employeeInventory.InventoryId != model.InventoryId)
                {
                    employeeInventory.EndDate = DateTime.Now;
                    EmployeeInventory ei = new EmployeeInventory
                    {
                        EmployeeId  = employee.Id,
                        InventoryId = model.InventoryId,
                        HireDate    = null
                    };
                    if (ei.InventoryId != null)
                    {
                        ei.HireDate = DateTime.Now;
                    }
                    _context.Add(ei);
                    _context.SaveChanges();
                }
            }

            EmployeeSalaries employeeSalaries = _context.EmployeeSalaries
                                                .Where(x => x.EmployeeId == employee.Id && x.EndDate == null)
                                                .FirstOrDefault();

            if (employeeSalaries.Value != model.Salary)
            {
                employeeSalaries.EndDate = DateTime.Now;
                EmployeeSalaries es = new EmployeeSalaries
                {
                    EmployeeId = employee.Id,
                    Value      = model.Salary,
                    StartDate  = DateTime.Now
                };
                _context.Add(es);
                _context.SaveChanges();
            }

            base.Edit(employee);
        }
Esempio n. 12
0
 public void Edit(DTOAttribute model)
 {
     try
     {
         Attribute attribute = _mapper.Map <Attribute>(model);
         _context.Update(attribute);
         _context.SaveChanges();
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
        public void Edit(DTOBrand dtoBrand)
        {
            Brand brand = _mapper.Map <Brand>(dtoBrand);

            _context.Update(brand);

            List <int>           itemsToAdd     = dtoBrand.SelectedCategoryBrandsIds;
            List <int>           itemsToDelete  = new List <int>();
            List <CategoryBrand> categoryBrands = _context.CategoriesBrands.Where(x => x.BrandId == brand.Id).ToList();

            foreach (var item in categoryBrands)
            {
                bool exist = itemsToAdd.Any(x => x == item.CategoryId);
                if (!exist)
                {
                    itemsToDelete.Add(item.Id);
                }
                else
                {
                    itemsToAdd.Remove(item.CategoryId);
                }
            }

            if (itemsToDelete != null && itemsToDelete.Any())
            {
                foreach (var item in itemsToDelete)
                {
                    _unitOfWork.CategoriesBrands.Delete(item); //TODO : Ubaciti provjeru da li je povezan sa nekim postojecim PROIZVODOM
                }
            }



            if (itemsToAdd != null && itemsToAdd.Any())
            {
                CategoryBrand categoryBrand = null;

                foreach (var item in itemsToAdd)
                {
                    categoryBrand = new CategoryBrand
                    {
                        BrandId    = brand.Id,
                        CategoryId = item
                    };
                    _context.CategoriesBrands.Add(categoryBrand);
                }
            }
            _context.SaveChanges();
        }
Esempio n. 14
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Sname,IC,Designation,Gender,DOB,Address,Postcode,City,State,Country,MobileNo,Email,Role,Floor,Department,TableNo,Status,Spoint,JoinedDate,Username,Pass")] Staff staff)
        {
            if (id != staff.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(staff);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!StaffExists(staff.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                ViewBag.StaffID   = HttpContext.Session.GetString("StaffID");
                ViewBag.StaffName = HttpContext.Session.GetString("StaffName");
                ViewBag.StaffRole = HttpContext.Session.GetString("StaffRole");
                if (HttpContext.Session.GetString("StaffRole") == "Admin")
                {
                    return(RedirectToAction("Index", "Staffs"));
                }
                else
                {
                    return(RedirectToAction("Index", "Home"));
                }
            }
            return(View(staff));
        }