// GET: RubberRoller
        public ActionResult Index(int?i)
        {
            LogAction.log(this._controllerName, "GET", "Requested RubberRoller-Index webpage", User.Identity.GetUserId());
            List <RubberRoller> rubberRollers = _db.rubberRollers.ToList();

            return(View(rubberRollers.ToPagedList(i ?? 1, 40)));
        }
        public ActionResult Edit(string staffID)
        {
            // If ID is not supplied redirect back to list
            if (staffID == null)
            {
                return(RedirectToAction("List"));
            }

            // Retrieve existing staff details from database
            ApplicationDbContext _db   = new ApplicationDbContext();
            ApplicationUser      staff = _db.Users.SingleOrDefault(c => c.staffID == staffID);

            // Ensure the retrieved value is not null
            if (staff == null || staff.Id == User.Identity.GetUserId())
            {
                return(RedirectToAction("List"));
            }

            UpdateViewModel returnModel = new UpdateViewModel
            {
                staffID  = staff.staffID,
                Email    = staff.Email,
                Id       = staff.Id,
                name     = staff.name,
                IC       = staff.IC,
                position = staff.position,
                status   = staff.status
            };

            ViewData["userPosition"] = getUserRoles();
            LogAction.log(this._controllerName, "GET", string.Format("Requested Account-Edit {0} webpage", staff.staffID), User.Identity.GetUserId());
            return(View("Edit", returnModel));
        }
示例#3
0
 public ActionResult Create(RollerCategory rollerCategory)
 {
     try
     {
         if (ModelState.IsValid)
         {
             _db.rollerCategories.Add(rollerCategory);
             int result = _db.SaveChanges();
             if (result > 0)
             {
                 TempData["formStatus"]    = true;
                 TempData["formStatusMsg"] = "<b>STATUS</b>: New rubber roller category has been successfully added!";
                 LogAction.log(this._controllerName, "POST", "Added new roller category record", User.Identity.GetUserId());
             }
         }
         return(Redirect(Request.UrlReferrer.ToString()));
     }
     catch (Exception ex)
     {
         TempData["formStatus"]    = false;
         TempData["formStatusMsg"] = "<b>ALERT</b>: Oops! Something went wrong. The rubber roller category has not been successfully added.";
         LogAction.log(this._controllerName, "POST", "Error: " + ex.Message, User.Identity.GetUserId());
         return(Redirect(Request.UrlReferrer.ToString()));
     }
 }
示例#4
0
        public ActionResult Index(int?i)
        {
            LogAction.log(this._controllerName, "GET", "Requested Maintenance-Index webpage", User.Identity.GetUserId());
            List <Maintenance> maintenances = _db.maintenances.OrderByDescending(m => m.reportDateTime).ToList();

            return(View(maintenances.ToPagedList(i ?? 1, 40)));
        }
        public ActionResult SummaryReport(int?i)
        {
            LogAction.log(this._controllerName, "GET", "Requested RubberRoller-SummaryReport webpage", User.Identity.GetUserId());
            List <RollerCategory> rollerCategories = _db.rollerCategories.ToList();

            return(View(rollerCategories.ToPagedList(i ?? 1, 40)));
        }
        // Displays a list of operation history
        public ActionResult OperationHistory(int?i)
        {
            LogAction.log(this._controllerName, "GET", "Requested Schedule-OperationHistory webpage", User.Identity.GetUserId());
            List <Schedule> schedules = _db.schedules.Where(s => s.status == ScheduleStatus.COMPLETED).ToList();

            return(View(schedules.ToPagedList(i ?? 1, 40)));
        }
示例#7
0
        public ActionResult Edit(int?id)
        {
            // Ensure ID is supplied
            if (id == null)
            {
                return(RedirectToAction("Index"));
            }

            // Retrieve existing specific maintenance record from database
            Maintenance maintenance = _db.maintenances.SingleOrDefault(c => c.maintenanceID == id);

            // Ensure the retrieved value is not null
            if (maintenance == null)
            {
                return(RedirectToAction("Index"));
            }

            if (maintenance.status != 1)
            {
                TempData["formStatus"]    = false;
                TempData["formStatusMsg"] = $"<b>ALERT</b>: Cannot edit a finalized maintenance report.";
                return(RedirectToAction("Index"));
            }

            LogAction.log(this._controllerName, "GET", $"Requested Maintenance-Edit {id} webpage", User.Identity.GetUserId());
            return(View("CreateEditMaintenance", maintenance));
        }
        public ActionResult RollerInformation(int?i)
        {
            List <RubberRoller> rubber = _db.rubberRollers.ToList();

            LogAction.log(this._controllerName, "GET", $"Requested roller information report", User.Identity.GetUserId());
            return(View(rubber.ToPagedList(i ?? 1, 40)));
        }
        // GET: Returns create form
        public ActionResult Create()
        {
            LogAction.log(this._controllerName, "GET", "Requested RubberRoller-Create webpage", User.Identity.GetUserId());

            // Retrieve roller category
            ViewData["rollerCatList"] = getRollerCategories();
            return(View("CreateEditForm"));
        }
示例#10
0
        public async Task <ActionResult> Index()
        {
            ApplicationDbContext _db = new ApplicationDbContext();
            var userId = User.Identity.GetUserId();
            var model  = _db.Users.FirstOrDefault(u => u.Id == userId);

            LogAction.log(this._controllerName, "GET", "Requested edit profile page", User.Identity.GetUserId());
            return(View(model));
        }
示例#11
0
        public ActionResult UpdateProfile(UpdateProfileViewModel user)
        {
            try
            {
                ApplicationDbContext _db = new ApplicationDbContext();
                var currentUserID        = User.Identity.GetUserId();
                var staff        = (ApplicationUser)UserManager.FindById(currentUserID);
                var ExStaff      = _db.Users.FirstOrDefault(u => u.staffID == user.staffID);
                var ExStaffEmail = _db.Users.FirstOrDefault(u => u.Email == user.Email);
                if (ExStaff != null)
                {
                    if (currentUserID != ExStaff.Id)
                    {
                        TempData["formStatus"]    = false;
                        TempData["formStatusMsg"] = $"<b>ALERT</b>: Staff ID has been taken by another staff.";
                        return(View("UpdateManagerProfile", user));
                    }
                }
                if (ExStaffEmail != null)
                {
                    if (currentUserID != ExStaffEmail.Id)
                    {
                        TempData["formStatus"]    = false;
                        TempData["formStatusMsg"] = $"<b>ALERT</b>: Email has been taken by another staff.";
                        return(View("UpdateManagerProfile", user));
                    }
                }

                staff.Email   = user.Email;
                staff.staffID = user.staffID;
                staff.name    = user.name;
                staff.IC      = user.IC;

                var result = UserManager.Update(staff);

                if (!result.Succeeded)
                {
                    ViewData["userPosition"]  = getUserRoles();
                    TempData["formStatus"]    = false;
                    TempData["formStatusMsg"] = $"<b>ALERT</b>: {result.Errors}";
                    return(RedirectToAction("Index"));
                }

                TempData["formStatus"]    = true;
                TempData["formStatusMsg"] = $"<b>STATUS</b>: Staff ({staff.staffID}) details has been successfully updated!";
                LogAction.log(this._controllerName, "POST", $"Staff ({staff.staffID}) details updated", User.Identity.GetUserId());
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                TempData["formStatus"]    = false;
                TempData["formStatusMsg"] = $"<b>ALERT</b>:{ex.Message} Oops! Something went wrong. Please try again later.";
                LogAction.log(this._controllerName, "POST", "Error: " + ex.Message, User.Identity.GetUserId());
                return(Redirect(Request.UrlReferrer.ToString()));
            }
        }
        public ActionResult Update(RubberRoller rubberRoller)
        {
            try
            {
                // Check if roller ID exist from DB
                var dbRoller = _db.rubberRollers.Where(r => r.rollerID == rubberRoller.rollerID && r.id != rubberRoller.id).FirstOrDefault();
                if (dbRoller != null)
                {
                    ViewData["rollerCatList"] = getRollerCategories();
                    ModelState.AddModelError("rollerID", "There is already an existing roller with the same roller ID.");
                    return(View("CreateEditForm", rubberRoller));
                }

                // Retrieve existing specific rubber roller from database
                RubberRoller rubberRoll = _db.rubberRollers.SingleOrDefault(c => c.id == rubberRoller.id);

                if (rubberRoll == null)
                {
                    return(RedirectToAction("Index"));
                }

                // Update rubber roller details
                if (rubberRoll.rollerID != rubberRoller.rollerID)
                {
                    rubberRoll.rollerID = rubberRoller.rollerID;
                }
                rubberRoll.rollerCategoryID = rubberRoller.rollerCategoryID;
                rubberRoll.type             = rubberRoller.type;
                rubberRoll.usage            = rubberRoller.usage;
                rubberRoll.shoreHardness    = rubberRoller.shoreHardness;
                rubberRoll.depthOfGroove    = rubberRoller.depthOfGroove;
                rubberRoll.diameter         = rubberRoller.diameter;
                rubberRoll.condition        = rubberRoller.condition;
                rubberRoll.remark           = rubberRoller.remark;
                rubberRoll.status           = rubberRoller.status;

                int result = _db.SaveChanges();

                if (result > 0)
                {
                    LogAction.log(this._controllerName, "POST", "Updated roller record", User.Identity.GetUserId());
                    TempData["formStatus"]    = true;
                    TempData["formStatusMsg"] = "<b>STATUS</b>: Rubber roller details has been successfully updated!";
                }

                return(Redirect(Request.UrlReferrer.ToString()));
            }
            catch (Exception ex)
            {
                LogAction.log(this._controllerName, "POST", "Error: " + ex.Message, User.Identity.GetUserId());
                TempData["formStatus"]    = false;
                TempData["formStatusMsg"] = "<b>ALERT</b>: Oops! Something went wrong. The rubber roller has not been successfully updated.";
                return(Redirect(Request.UrlReferrer.ToString()));
            }
        }
        public ActionResult ViewOperationDetail(int id)
        {
            Schedule schedule = _db.schedules.FirstOrDefault(s => s.scheduleID == id);

            if (id == 0 || schedule == null)
            {
                return(Redirect(Request.UrlReferrer.ToString()));
            }
            LogAction.log(this._controllerName, "GET", "Requested Schedule-ViewOperationDetail webpage", User.Identity.GetUserId());
            return(View(schedule));
        }
        public ActionResult MarkOperationComplete(int?id)
        {
            Schedule schedule = _db.schedules.FirstOrDefault(s => s.scheduleID == id);

            if (id == 0 || schedule == null)
            {
                return(Redirect(Request.UrlReferrer.ToString()));
            }
            ViewData["schedule"] = schedule;
            LogAction.log(this._controllerName, "GET", "Requested Schedule-AfterChecklistForm form webpage", User.Identity.GetUserId());
            return(View("AfterChecklist"));
        }
        public ActionResult StockDetails(int id, int?i)
        {
            if (id == 0)
            {
                return(Redirect(Request.UrlReferrer.ToString()));
            }

            LogAction.log(this._controllerName, "GET", $"Requested RubberRoller-StockDetails {id} webpage", User.Identity.GetUserId());
            List <RubberRoller> rubberRollers = _db.rubberRollers.Where(r => r.rollerCategoryID == id).ToList();

            return(View(rubberRollers.ToPagedList(i ?? 1, 40)));
        }
        public ActionResult CreateSchedule(int?id)
        {
            RubberRoller rubberRoller = _db.rubberRollers.FirstOrDefault(r => r.id == id);

            if (rubberRoller == null || rubberRoller.status != RollerStatus.getStatus(RollerStatus.IN_STORE_ROOM))
            {
                return(RedirectToAction("CreateSearch"));
            }
            ViewData["roller"] = rubberRoller;
            LogAction.log(this._controllerName, "GET", "Requested Schedule-CreateSchedule webpage", User.Identity.GetUserId());
            return(View("ScheduleCreateEditForm"));
        }
示例#17
0
        public ActionResult CreateConfirm(FormCollection collection, HttpPostedFileBase file)
        {
            try
            {
                Maintenance  maintenance = new Maintenance();
                int          rollID      = Int32.Parse(collection["rollerID"]);
                RubberRoller rubber      = _db.rubberRollers.FirstOrDefault(r => r.id == rollID);
                if (rubber == null)
                {
                    return(RedirectToAction("CreateSearch"));
                }

                maintenance.title          = collection["title"];
                maintenance.rollerID       = rubber.id;
                maintenance.RubberRoller   = rubber;
                maintenance.sendTo         = collection["sendTo"];
                maintenance.diameterRoller = Double.Parse(collection["diameterRoller"]);
                maintenance.diameterCore   = Double.Parse(collection["diameterCore"]);
                if (collection["openingStockDate"].Length > 0)
                {
                    maintenance.openingStockDate = DateTime.Parse(collection["openingStockDate"]);
                }
                else
                {
                    maintenance.openingStockDate = null;
                }
                maintenance.lastProductionLine = collection["lastProdLine"];
                maintenance.totalMileage       = (collection["totalMileage"] == "0" ? 0 : Int32.Parse(collection["totalMileage"]));
                maintenance.reason             = collection["reason"];
                maintenance.remark             = collection["remark"];
                maintenance.newDiameter        = Double.Parse(collection["newDiameter"]);
                maintenance.newShoreHardness   = collection["newShoreHardness"];
                maintenance.correctiveAction   = collection["correctiveAction"];
                maintenance.sendForRefurbished = Boolean.Parse(collection["sendForRefurbished"]);
                maintenance.reportDateTime     = DateTime.Now;

                if (file != null && file.ContentLength > 0 && imgFormats.Any(item => file.FileName.EndsWith(item, StringComparison.OrdinalIgnoreCase)))
                {
                    maintenance.imagePath = UploadImage(file);
                }

                LogAction.log(this._controllerName, "GET", "Redirect Maintenance-CreateConfirm webpage", User.Identity.GetUserId());
                return(View(maintenance));
            }
            catch (Exception ex)
            {
                LogAction.log(this._controllerName, "POST", $"Error: {ex.Message}", User.Identity.GetUserId());
                return(RedirectToAction("CreateSearch"));
            }
        }
示例#18
0
        public ActionResult RollerReceived(FormCollection collection)
        {
            try
            {
                var         ID          = Int32.Parse(collection["maintenanceID"]);
                Maintenance maintenance = _db.maintenances.FirstOrDefault(m => m.maintenanceID == ID);
                if (maintenance == null || maintenance.status != 2)
                {
                    return(Redirect(Request.UrlReferrer.ToString()));
                }

                var             uID  = User.Identity.GetUserId();
                ApplicationUser user = _db.Users.FirstOrDefault(u => u.Id == uID);

                maintenance.status = 4;
                maintenance.RubberRoller.status = RollerStatus.getStatus(2);

                // Set roller isRefurbish status
                if (maintenance.sendForRefurbished)
                {
                    maintenance.RubberRoller.isRefurbished = true;
                }

                // Update roller location record
                bool updateLocatResult = CentralUtilities.UpdateRollerLocation(maintenance.RubberRoller, collection["rackLocation"]);

                int result = _db.SaveChanges();
                if (result > 0 && updateLocatResult)
                {
                    TempData["formStatus"]    = true;
                    TempData["formStatusMsg"] = $"<b>STATUS</b>: Roller {maintenance.RubberRoller.rollerID} has been received back from maintenance.";
                    LogAction.log(this._controllerName, "POST", $"Roller {maintenance.RubberRoller.rollerID} has been received back from maintenance", User.Identity.GetUserId());
                }
                else
                {
                    TempData["formStatus"]    = false;
                    TempData["formStatusMsg"] = $"<b>ALERT</b>: Oops! Something went wrong. Unable to mark maintenance report #{ID} as completed.";
                    LogAction.log(this._controllerName, "POST", $"Error marking maintenance report #{maintenance.maintenanceID} as completed", User.Identity.GetUserId());
                }
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                TempData["formStatus"]    = false;
                TempData["formStatusMsg"] = $"<b>ALERT</b>: Oops! Something went wrong.";
                LogAction.log(this._controllerName, "POST", $"Error marking maintenance report as completed {ex.Message}", User.Identity.GetUserId());
                return(RedirectToAction("Index"));
            }
        }
        public ActionResult CreateSchedule(Schedule schedule, FormCollection collection)
        {
            Schedule existingSched = _db.schedules.FirstOrDefault(s => s.rollerID == schedule.rollerID && s.startDateTime == schedule.startDateTime && s.operationLine == schedule.operationLine);

            if (existingSched != null)
            {
                ViewData["schedule"] = existingSched;
                return(View("BeforeChecklist"));
            }

            RubberRoller rubberRoller = _db.rubberRollers.FirstOrDefault(r => r.id == schedule.rollerID);

            schedule.RubberRoller        = rubberRoller;
            schedule.tinplateSize        = $"{collection["thickness"]}x{collection["width"]}x{collection["length"]}";
            schedule.status              = ScheduleStatus.PENDING_BEFORE_CHECKLIST;
            schedule.RubberRoller.status = RollerStatus.getStatus(RollerStatus.IN_USE);

            // Update roller opening stock date
            if (rubberRoller.opening_stock_date == null || rubberRoller.isRefurbished)
            {
                rubberRoller.opening_stock_date = DateTime.Now;
            }

            // Reset roller isRefurbish status
            if (rubberRoller.isRefurbished)
            {
                rubberRoller.isRefurbished = false;
            }

            _db.schedules.Add(schedule);

            int result = _db.SaveChanges();

            if (result > 0)
            {
                TempData["formStatus"]    = true;
                TempData["formStatusMsg"] = "<b>STATUS</b>: New schedule record has been successfully added.";
                ViewData["schedule"]      = schedule;
                LogAction.log(this._controllerName, "POST", "New schedule details successfully added", User.Identity.GetUserId());
                return(View("BeforeChecklist"));
            }
            else
            {
                TempData["formStatus"]    = false;
                TempData["formStatusMsg"] = "<b>ALERT</b>: Oops! Something went wrong. The schedule record has not been successfully added.";
                LogAction.log(this._controllerName, "POST", "Errpr adding wew schedule detail.", User.Identity.GetUserId());
                return(Redirect(Request.UrlReferrer.ToString()));
            }
        }
        public ActionResult RollerUsageSearch()
        {
            // Retrieve rollers
            var rubberRollers = _db.rubberRollers
                                .AsEnumerable()
                                .Select(r => new
            {
                ID       = r.id,
                rollerID = $"{r.rollerID} - {r.RollerCategory.size} {r.RollerCategory.description}"
            }).ToList();

            ViewData["rollerList"] = new SelectList(rubberRollers, "ID", "rollerID");
            LogAction.log(this._controllerName, "GET", "Requested Report-RollerUsageSearch webpage", User.Identity.GetUserId());
            return(View());
        }
        public ActionResult LocationHistory(int id, int?i)
        {
            if (id == 0)
            {
                return(RedirectToAction("Index"));
            }

            LogAction.log(this._controllerName, "GET", $"Requested webpage RubberRoller-LocationHistory for Roller: {id}", User.Identity.GetUserId());
            RubberRoller rubberRollers = _db.rubberRollers.FirstOrDefault(r => r.id == id);

            ViewData["rollerID"] = rubberRollers.rollerID;
            List <RollerLocation> rollerLocations = rubberRollers.RollerLocations.ToList();

            return(View(rollerLocations.ToPagedList(i ?? 1, 40)));
        }
        public ActionResult StockCard(RubberRoller rubberRoller, int?i)
        {
            RubberRoller rubber = _db.rubberRollers.FirstOrDefault(r => r.id == rubberRoller.id);

            if (rubber == null)
            {
                return(RedirectToAction("StockCardSearch"));
            }

            LogAction.log(this._controllerName, "GET", $"Requested stock card for Roller: {rubber.id}", User.Identity.GetUserId());
            ViewData["rollerID"] = rubber.rollerID;
            List <RollerLocation> rollerLocations = rubber.RollerLocations.ToList();

            return(View(rollerLocations.ToPagedList(i ?? 1, 40)));
        }
        // GET: RubberRoller
        public ActionResult StockOverview(int?i)
        {
            LogAction.log(this._controllerName, "GET", "Requested RubberRoller-StockOverview webpage", User.Identity.GetUserId());
            List <RollerCategory> rollerCategories = _db.rollerCategories.ToList();
            int count = 0;

            foreach (var rollerCat in rollerCategories)
            {
                if (rollerCat.RubberRollers.Count < rollerCat.minAmount)
                {
                    count++;
                }
            }
            TempData["totalBelowMinAmount"] = count;
            return(View(rollerCategories.ToPagedList(i ?? 1, 40)));
        }
        // Display search roller form - 1st step of adding a new schedule/operation
        public ActionResult CreateSearch()
        {
            // Retrieve rollers
            var rubberRollers = _db.rubberRollers
                                .AsEnumerable()
                                .Select(r => new
            {
                ID       = r.id,
                rollerID = $"{r.rollerID} - {r.RollerCategory.size} {r.RollerCategory.description}",
                r.status
            }).Where(r => r.status == RollerStatus.getStatus(RollerStatus.IN_STORE_ROOM)).ToList();

            ViewData["rollerList"] = new SelectList(rubberRollers, "ID", "rollerID");
            LogAction.log(this._controllerName, "GET", "Requested Schedule-CreateSearch webpage", User.Identity.GetUserId());
            return(View("SearchRoller"));
        }
示例#25
0
        public ActionResult ViewMaintenanceReport(int id)
        {
            LogAction.log(this._controllerName, "GET", "Requested Maintenance-ViewMaintenanceReport webpage", User.Identity.GetUserId());
            if (id == 0)
            {
                return(RedirectToAction("Index"));
            }

            Maintenance maintenance = _db.maintenances.FirstOrDefault(m => m.maintenanceID == id);

            if (maintenance == null)
            {
                return(RedirectToAction("Index"));
            }
            return(View(maintenance));
        }
示例#26
0
        // GET: Returns create form
        public ActionResult Create(RubberRoller rubberRoller)
        {
            RubberRoller rubber = _db.rubberRollers.FirstOrDefault(r => r.id == rubberRoller.id);

            if (rubber == null ||
                (rubber.status != RollerStatus.getStatus(RollerStatus.IN_STORE_ROOM) &&
                 rubber.status != RollerStatus.getStatus(RollerStatus.IN_STORE_ROOM_ON_HOLD)
                )
                )
            {
                return(RedirectToAction("CreateSearch"));
            }

            ViewData["rubber"] = rubber;
            LogAction.log(this._controllerName, "GET", "Requested Maintenance-Create form webpage", User.Identity.GetUserId());
            return(View("CreateEditMaintenance"));
        }
示例#27
0
        public ActionResult ApproveReport(FormCollection collection)
        {
            try
            {
                var         ID          = Int32.Parse(collection["maintenanceID"]);
                Maintenance maintenance = _db.maintenances.FirstOrDefault(m => m.maintenanceID == ID);
                if (maintenance == null || maintenance.status == 2)
                {
                    return(Redirect(Request.UrlReferrer.ToString()));
                }

                var             uID  = User.Identity.GetUserId();
                ApplicationUser user = _db.Users.FirstOrDefault(u => u.Id == uID);

                maintenance.status              = 2;
                maintenance.statusRemark        = null;
                maintenance.approveDateTime     = DateTime.Now;
                maintenance.verfiedBy           = user;
                maintenance.RubberRoller.status = RollerStatus.getStatus(5);

                // Update roller location record
                bool updateLocatResult = CentralUtilities.UpdateRollerLocation(maintenance.RubberRoller, $"Sent to {maintenance.sendTo} for maintenance");

                int result = _db.SaveChanges();
                if (result > 0 && updateLocatResult)
                {
                    TempData["formStatus"]    = true;
                    TempData["formStatusMsg"] = $"<b>STATUS</b>: Maintenance report #{ID} has been successfully approved.";
                    LogAction.log(this._controllerName, "POST", $"Approved maintenance report #{maintenance.maintenanceID}", User.Identity.GetUserId());
                }
                else
                {
                    TempData["formStatus"]    = false;
                    TempData["formStatusMsg"] = $"<b>ALERT</b>: Oops! Something went wrong. Maintenance report #{ID} has not been successfully approved.";
                    LogAction.log(this._controllerName, "POST", $"Error approving maintenance report #{maintenance.maintenanceID}", User.Identity.GetUserId());
                }
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                TempData["formStatus"]    = false;
                TempData["formStatusMsg"] = $"<b>ALERT</b>: Oops! Something went wrong.";
                LogAction.log(this._controllerName, "POST", $"Error approving maintenance report: {ex.Message}", User.Identity.GetUserId());
                return(RedirectToAction("Index"));
            }
        }
示例#28
0
        public ActionResult Update(Maintenance maintenance, HttpPostedFileBase file)
        {
            try
            {
                // Retrieve existing maintenance report from database
                Maintenance main = _db.maintenances.SingleOrDefault(m => m.maintenanceID == maintenance.maintenanceID);

                if (main == null)
                {
                    return(RedirectToAction("Index"));
                }

                main.title              = maintenance.title;
                main.diameterCore       = maintenance.diameterCore;
                main.sendTo             = maintenance.sendTo;
                main.sendForRefurbished = maintenance.sendForRefurbished;
                main.reason             = maintenance.reason;
                main.remark             = maintenance.remark;
                main.newDiameter        = maintenance.newDiameter;
                main.newShoreHardness   = maintenance.newShoreHardness;
                main.correctiveAction   = maintenance.correctiveAction;
                if (file != null && file.ContentLength > 0 && imgFormats.Any(item => file.FileName.EndsWith(item, StringComparison.OrdinalIgnoreCase)))
                {
                    main.imagePath = UploadImage(file);
                }

                int result = _db.SaveChanges();

                if (result > 0)
                {
                    LogAction.log(this._controllerName, "POST", $"Updated maintenance #{maintenance} record", User.Identity.GetUserId());
                    TempData["formStatus"]    = true;
                    TempData["formStatusMsg"] = $"<b>STATUS</b>: Maintenance Report #{maintenance.maintenanceID} has been successfully updated!";
                }

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                LogAction.log(this._controllerName, "POST", "Error: " + ex.Message, User.Identity.GetUserId());
                TempData["formStatus"]    = false;
                TempData["formStatusMsg"] = $"<b>ALERT</b>: Oops! Something went wrong. The maintenance report #{maintenance.maintenanceID} has not been successfully updated.";
                return(Redirect(Request.UrlReferrer.ToString()));
            }
        }
        public ActionResult MaintenanceHistory(int id, int?i)
        {
            if (id == 0)
            {
                return(RedirectToAction("Index"));
            }

            LogAction.log(this._controllerName, "GET", $"Requested webpage RubberRoller-MaintenanceHistory for Roller: {id}", User.Identity.GetUserId());
            RubberRoller rubberRollers = _db.rubberRollers.FirstOrDefault(r => r.id == id);

            ViewData["rollerID"] = rubberRollers.rollerID;
            List <Maintenance> maintenances = rubberRollers.Maintenances
                                              .Where(m => m.rollerID == id)
                                              .Where(m => m.status == RollerMaintenance.APPROVED || m.status == RollerMaintenance.COMPLETED)
                                              .ToList();

            return(View(maintenances.ToPagedList(i ?? 1, 40)));
        }
示例#30
0
        public ActionResult UpdateProfile()
        {
            ApplicationDbContext _db = new ApplicationDbContext();
            var userId = User.Identity.GetUserId();
            var staff  = _db.Users.FirstOrDefault(u => u.Id == userId);
            UpdateProfileViewModel returnModel = new UpdateProfileViewModel
            {
                staffID = staff.staffID,
                Email   = staff.Email,

                name     = staff.name,
                IC       = staff.IC,
                position = staff.position
            };

            LogAction.log(this._controllerName, "GET", "Requested edit profile page", User.Identity.GetUserId());
            return(View("UpdateManagerProfile", returnModel));
        }