public async Task <IActionResult> AddItem(string itemNumber, int quantity)
        {
            //var q = context.Catalogue.Where(x => x.ItemName == itemName).FirstOrDefault();
            //string itemNumber = q.ItemNumber;

            bool checkItemExists = false;
            var  q = context.RecordDetails.Where(x => x.Rrid == rrid).ToList();

            foreach (RecordDetails current in q)
            {
                if (current.ItemNumber == itemNumber)
                {
                    checkItemExists  = true;
                    current.Quantity = current.Quantity + quantity;
                    await context.SaveChangesAsync();

                    break;
                }
            }
            if (checkItemExists == false)
            {
                RecordDetails r = new RecordDetails();
                r.Rrid       = rrid;
                r.ItemNumber = itemNumber;
                r.Quantity   = quantity;
                context.Add(r);
                await context.SaveChangesAsync();

                return(RedirectToAction("Edit", new { id = rrid }));
            }
            else
            {
                return(RedirectToAction("Edit", new { id = rrid }));
            }
        }
示例#2
0
        public async Task <IActionResult> Create([Bind("SupplierCode,SupplierName,GstregistrationNo,TitleOfCourtesy,ContactName,PhoneNo,FaxNo,Address,City,PostalCode")] Supplier supplier)
        {
            if (ModelState.IsValid)
            {
                _context.Add(supplier);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(supplier));
        }
示例#3
0
        public async Task <IActionResult> Create([Bind("UserId,TitleOfCourtesy,Name,DepartmentCode,Telephone,Fax,EmailAddress")] User user)
        {
            if (ModelState.IsValid)
            {
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["DepartmentCode"] = new SelectList(_context.Department, "DepartmentCode", "DepartmentCode", user.DepartmentCode);
            return(View(user));
        }
示例#4
0
        //TEST FOR ANDROID - Assign Deputy
        public void saveDeputy(string dept, string name, DateTime startDate, DateTime endDate)
        {
            Department department = context.Department.Where(x => x.DepartmentCode == dept).First();
            User       u          = context.User.Where(x => x.Name == name).First();

            Models.DepartmentCoveringHeadRecord d2 = new Models.DepartmentCoveringHeadRecord();
            d2.UserId    = u.UserId;
            d2.StartDate = startDate;
            d2.EndDate   = endDate;
            department.CoveringHeadId = u.UserId;
            context.Add(d2);
            context.SaveChanges();
        }
        public async Task <IActionResult> Create([Bind("Dlid,StartDate,EstDeliverDate,CompleteDate,DepartmentCode,RepId,CollectionPointId,Status")] DisbursementList disbursementList)
        {
            if (ModelState.IsValid)
            {
                _context.Add(disbursementList);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CollectionPointId"] = new SelectList(_context.CollectionPoint, "CollectionPointId", "CollectionPointName", disbursementList.CollectionPointId);
            ViewData["DepartmentCode"]    = new SelectList(_context.Department, "DepartmentCode", "DepartmentCode", disbursementList.DepartmentCode);
            //ViewData["RepId"] = new SelectList(_context.User, "UserId", "DepartmentCode", disbursementList.RepId);
            return(View(disbursementList));
        }
示例#6
0
        public IActionResult Index(User u, DateTime startdate, DateTime enddate)
        {
            if (startdate > enddate || startdate < DateTime.Now.Date.AddDays(-1))
            {
                TempData["DateAlert"] = "Please enter valid dates!";
                return(RedirectToAction("Index"));
            }
            else
            {
                if (ModelState.IsValid)
                {
                    Models.Department d1 = context.Department.Where(x => x.DepartmentCode == dept).First();
                    d1.CoveringHeadId = u.UserId;

                    if (edit == true)
                    {
                        var q = context.DepartmentCoveringHeadRecord.Where(x => x.UserId == currentDeputyHeadId).First();
                        Models.DepartmentCoveringHeadRecord d2 = new Models.DepartmentCoveringHeadRecord();
                        d2           = q;
                        d2.UserId    = u.UserId;
                        d2.StartDate = startdate;
                        d2.EndDate   = enddate;
                    }
                    else
                    {
                        Models.DepartmentCoveringHeadRecord d2 = new Models.DepartmentCoveringHeadRecord();
                        d2.UserId    = u.UserId;
                        d2.StartDate = startdate;
                        d2.EndDate   = enddate;
                        context.Add(d2);
                    }
                    context.SaveChanges();
                    TempData["Success"] = "Edits Saved Successfully";
                    return(RedirectToAction("Index"));
                }
                return(RedirectToAction("Index"));
            }
        }
        public async Task <IActionResult> Create([Bind("ItemNumber,Category,ItemName,ReorderLevel,ReorderQty,UnitOfMeasure,Stock,Out,Supplier1,Supplier2,Supplier3,Supplier1Price,Supplier2Price,Supplier3Price")] Catalogue catalogue)
        {
            //Viewbag for supplier1 dropdown list, need to post back
            List <Supplier> supplier1List = _context.Supplier.ToList();

            supplier1List.Insert(0, new Supplier {
                SupplierCode = "---Select Supplier---", SupplierName = "---Select Supplier---"
            });
            ViewBag.Supplier1 = supplier1List;
            List <Supplier> supplier2List = _context.Supplier.ToList();

            supplier1List.Insert(0, new Supplier {
                SupplierCode = "---Select Supplier---", SupplierName = "---Select Supplier---"
            });
            ViewBag.Supplier2 = supplier2List;
            List <Supplier> supplier3List = _context.Supplier.ToList();

            supplier3List.Insert(0, new Supplier {
                SupplierCode = "---Select Supplier---", SupplierName = "---Select Supplier---"
            });
            ViewBag.Supplier3 = supplier3List;


            if (ModelState.IsValid)
            {
                _context.Add(catalogue);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                TempData["EmptyError"] = "Please fill in all details!";
                return(RedirectToAction("Create"));
            }
            //return View(catalogue);
        }
示例#8
0
        public async Task <IActionResult> Index(User u, DateTime startdate, DateTime enddate)
        {
            DateTime dtpDefault = new DateTime(0001, 1, 1, 0, 0, 0);

            if (startdate != null && enddate != null)
            {
                if (startdate.Equals(dtpDefault) || enddate.Equals(dtpDefault))
                {
                    TempData["NoDetails"] = "Please fill in all details.";
                    @ViewData["Show"]     = null;
                    return(RedirectToAction("Index"));
                }
                if (startdate <= enddate && startdate >= DateTime.Now.Date && enddate >= DateTime.Now.Date)
                {
                    if (ModelState.IsValid)
                    {
                        Models.Department d1 = context.Department.Where(x => x.DepartmentCode == dept).First();
                        d1.CoveringHeadId = u.UserId;

                        if (edit == true)
                        {
                            var q = context.DepartmentCoveringHeadRecord.Where(x => x.UserId == currentDeputyHeadId).FirstOrDefault();
                            Models.DepartmentCoveringHeadRecord d2 = new Models.DepartmentCoveringHeadRecord();
                            d2           = q;
                            d2.UserId    = u.UserId;
                            d2.StartDate = startdate;
                            d2.EndDate   = enddate;

                            context.SaveChanges();
                            TempData["EditSuccess"] = "Changes were saved successfully!";

                            //send email to old deputy head
                            var    oldhead = context.User.Where(x => x.UserId == currentDeputyHeadId).First();
                            string email2  = oldhead.EmailAddress;
                            await _emailSender.SendEmailAsync(email2, "Department Deputy Head Replacement", "Dear " + oldhead.Name + ",<br>You have been replaced as department deputy head.");
                        }
                        else
                        {
                            Models.DepartmentCoveringHeadRecord d2 = new Models.DepartmentCoveringHeadRecord();
                            d2.UserId    = u.UserId;
                            d2.StartDate = startdate;
                            d2.EndDate   = enddate;
                            context.Add(d2);
                            context.SaveChanges();
                            TempData["NewSuccess"] = "New deputy head appointed!";

                            //send email to new deputy head
                            var    newhead = context.User.Where(x => x.UserId == u.UserId).First();
                            string email   = newhead.EmailAddress;
                            await _emailSender.SendEmailAsync(email, "Department Deputy Head Appointment", "Dear " + newhead.Name + ",<br>You have been appointed as the department deputy head.");
                        }
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        TempData["FilterError"] = "Assignment was not completed. Please try again.";
                        return(RedirectToAction("Index"));
                    }
                }
                else
                {
                    if (startdate > enddate && (startdate < DateTime.Now.Date || enddate < DateTime.Now.Date))
                    {
                        TempData["StartAndEndDateError"] = "End date cannot be earlier than start date. Start date and end date cannot be earlier than today. Please try again.";
                        return(RedirectToAction("Index"));
                    }
                    if (startdate > enddate)
                    {
                        TempData["EndDateError"] = "End date cannot be earlier than start date. Please try again.";
                        return(RedirectToAction("Index"));
                    }
                    if (startdate < DateTime.Now.Date || enddate < DateTime.Now.Date)
                    {
                        TempData["StartDateError"] = "Start date and end date cannot be earlier than today. Please try again.";
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        TempData["NoDetails"] = "Please fill in all details!";
                        return(RedirectToAction("Index"));
                    }
                }
            }
            else
            {
                TempData["NoDetails"] = "Please fill in all details!";
                return(RedirectToAction("Index"));
            }
        }