Пример #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.Add(DTOInventory inventory)
        {
            PhoneNumber phone   = inventory.PhoneNumber;
            Address     address = _mapper.Map <Address>(inventory.Address);
            Inventory   i       = _mapper.Map <Inventory>(inventory);

            _context.Add(phone);
            _context.Add(address);
            _context.SaveChanges();

            i.PhoneNumberId = phone.Id;
            i.AddressId     = address.Id;
            _context.Add(i);
            _context.SaveChanges();
        }
Пример #3
0
        public void Add(DTOExport model)
        {
            if (model.InventoryId == 0 || model.EmployeeId == 0 || model.CustomerId == 0)
            {
                return;
            }

            Export export = _mapper.Map <Export>(model);
            List <ExportDetail> exportDetails = _mapper.Map <List <ExportDetail> >(model.ExportProductList);

            if (model.InventoryId > 0 && model.EmployeeId > 0)
            {
                export.EmployeeId = model.EmployeeId;
            }
            _context.Add(export);
            _context.SaveChanges();

            if (exportDetails != null)
            {
                foreach (var ed in exportDetails)
                {
                    ed.ExportId = export.Id;
                    double productPrice = _context.ProductPrices
                                          .Where(x => x.ProductId == ed.ProductId && !x.IsDeleted)
                                          .FirstOrDefault().Price;
                    ed.Price = ed.Quantity * productPrice - (ed.Quantity * productPrice * ed.Discount / 100);
                }
                _context.AddRange(exportDetails);
                _context.SaveChanges();
            }
        }
Пример #4
0
        public void Add(DTOCustomer model)
        {
            Address      address  = _mapper.Map <Address>(model.Address);
            PhoneNumber  phone    = model.PhoneNumber;
            EmailAddress email    = model.EmailAddress;
            Customer     customer = _mapper.Map <Customer>(model);

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

            customer.AddressId      = address.Id;
            customer.PhoneNumberId  = phone.Id;
            customer.EmailAddressId = email.Id;

            base.Add(customer);
        }
Пример #5
0
        public void Add(DTOSupplier model)
        {
            Address      address  = _mapper.Map <Address>(model.Address);
            PhoneNumber  phone    = model.PhoneNumber;
            EmailAddress email    = model.EmailAddress;
            Supplier     supplier = _mapper.Map <Supplier>(model);

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

            supplier.AddressId      = address.Id;
            supplier.PhoneNumberId  = phone.Id;
            supplier.EmailAddressId = email.Id;

            _context.Add(supplier);
            _context.SaveChanges();
        }
Пример #6
0
        public async Task <IActionResult> Create([Bind("Id,ProductName,PartNumber,ProductLabel,StartingInventory,InventoryReceived,InventoryShipped,InventoryOnHand,MinimumRequired")] Products products)
        {
            if (ModelState.IsValid)
            {
                _context.Add(products);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(products));
        }
Пример #7
0
        public async Task <IActionResult> Create([Bind("Id,Supplier")] Suppliers suppliers)
        {
            if (ModelState.IsValid)
            {
                _context.Add(suppliers);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(suppliers));
        }
Пример #8
0
        public async Task <IActionResult> Create([Bind("Id,Title,First,Middle,Last,ProductId,NumberShipped,OrderDate")] Orders orders)
        {
            if (ModelState.IsValid)
            {
                _context.Add(orders);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(orders));
        }
Пример #9
0
 public void Add(DTOAttribute model)
 {
     try
     {
         Attribute attribute = _mapper.Map <Attribute>(model);
         _context.Add(attribute);
         _context.SaveChanges();
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
Пример #10
0
        public async Task <IActionResult> Create([Bind("Id,SupplierId,ProductId,NumberReceived,PurchaseDate")] Purchases purchases)
        {
            if (ModelState.IsValid)
            {
                _context.Add(purchases);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProductId"]  = new SelectList(_context.Products, "Id", "ProductName", purchases.ProductId);
            ViewData["SupplierId"] = new SelectList(_context.Suppliers, "Id", "Supplier", purchases.SupplierId);
            return(View(purchases));
        }
        public void Add(DTOCategory dtoCategory)
        {
            Category category = _mapper.Map <Category>(dtoCategory);

            _context.Add(category);
            _context.SaveChanges();

            CategoryBrand categoryBrand = null;

            foreach (var cb in dtoCategory.SelectedCategoryBrandsIds)
            {
                categoryBrand = new CategoryBrand
                {
                    CategoryId = category.Id,
                    BrandId    = cb
                };

                _context.CategoriesBrands.Add(categoryBrand);
            }

            _context.SaveChanges();
        }
        public void Add(DTOBrand dtoBrand)
        {
            Brand brand = _mapper.Map <Brand>(dtoBrand);

            _context.Add(brand);
            _context.SaveChanges();
            if (dtoBrand.SelectedCategoryBrandsIds != null && dtoBrand.SelectedCategoryBrandsIds.Any())
            {
                CategoryBrand categoryBrand = null;
                foreach (var cb in dtoBrand.SelectedCategoryBrandsIds)
                {
                    categoryBrand = new CategoryBrand
                    {
                        BrandId    = brand.Id,
                        CategoryId = cb,
                    };

                    _context.CategoriesBrands.Add(categoryBrand);
                }
            }

            _context.SaveChanges();
        }
Пример #13
0
        public async Task <IActionResult> Create([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)
        {
            Boolean Validate     = true;
            var     userToVerify = await _context.Staff.SingleOrDefaultAsync(s => s.Username == staff.Username);

            if (userToVerify != null)
            {
                Validate = true;
            }
            else
            {
                Validate = false;
            }
            if (Validate)
            {
                ModelState.AddModelError("Error", "Username Already Exits");
                return(View());
            }
            else if (ModelState.IsValid)
            {
                staff.JoinedDate = DateTime.Now.Date;
                DateTime.Now.Date.ToString("MM / dd / yyyy");
                _context.Add(staff);
                await _context.SaveChangesAsync();

                ViewBag.StaffID   = HttpContext.Session.GetString("StaffID");
                ViewBag.StaffName = HttpContext.Session.GetString("StaffName");
                ViewBag.StaffRole = HttpContext.Session.GetString("StaffRole");

                //TempData["ID"] = staffDetail.ID;
                //TempData["Name"] = staffDetail.Sname;
                //TempData["Role"] = staffDetail.Role;

                return(RedirectToAction("Index", "Staffs"));
            }
            return(View(staff));
        }
        public void Add(DTOEmployee model)
        {
            Address  address  = _mapper.Map <Address>(model.Address);
            Employee employee = _mapper.Map <Employee>(model);

            _context.Addresses.Add(address);
            _context.SaveChanges();

            employee.AddressId = address.Id;
            employee.Username  = model.FirstName.ToLower() + model.LastName.Substring(0, 1).ToLower();
            int b = 0;

            foreach (var x in _context.Users.ToList())
            {
                if (x.UserName == employee.Username)
                {
                    b++;
                }
            }
            if (b > 0)
            {
                employee.Username += b.ToString();
            }
            employee.PasswordHash = "AQAAAAEAACcQAAAAEA27GXFgUsI5e3+EHt0MSqROepea6LqlbFSugDckdIrVK+MyaYbiqZABm4qUmjep+A==";
            _context.Add(employee);
            _context.SaveChanges();

            EmployeeInventory employeeInventory = new EmployeeInventory
            {
                EmployeeId  = employee.Id,
                InventoryId = model.InventoryId,
                HireDate    = null,
                EndDate     = null
            };

            if (employeeInventory.InventoryId != null)
            {
                employeeInventory.HireDate = DateTime.Now;
            }
            _context.Add(employeeInventory);
            _context.SaveChanges();

            EmployeeSalaries employeeSalary = new EmployeeSalaries
            {
                EmployeeId = employee.Id,
                Value      = model.Salary,
                StartDate  = DateTime.Now,
                EndDate    = null
            };

            _context.Add(employeeSalary);
            _context.SaveChanges();

            ApplicationUser user = new ApplicationUser
            {
                UserName           = employee.Username,
                NormalizedUserName = employee.Username.ToUpper(),
                Email                = employee.Username + "@ims.ba",
                NormalizedEmail      = (employee.Username + "@ims.ba").ToUpper(),
                EmailConfirmed       = true,
                PhoneNumber          = employee.PhoneNumber,
                PhoneNumberConfirmed = false,
                PasswordHash         = employee.PasswordHash,
                SecurityStamp        = Guid.NewGuid().ToString(),
                ConcurrencyStamp     = Guid.NewGuid().ToString()
            };

            _context.Users.Add(user);
            _context.SaveChanges();

            ApplicationUserRole userRole = new ApplicationUserRole
            {
                UserId = user.Id,
                RoleId = 2
            };

            _context.UserRoles.Add(userRole);
            _context.SaveChanges();

            Person person = new Person
            {
                Active         = true,
                CreatedDate    = DateTime.Now,
                FirstName      = employee.FirstName,
                LastName       = employee.LastName,
                GenderId       = employee.GenderId,
                PhoneNumber    = employee.PhoneNumber,
                IdentityUserId = user.Id
            };

            _context.Persons.Add(person);
            _context.SaveChanges();
        }