public async Task <ActionResult> AddNote(int equipmentId, string entityType, int?entityId, string noteText, string controllerId)
        {
            try
            {
                var equipment = db.Equipment.Include(x => x.Status)
                                .FirstOrDefault(x => x.Id == equipmentId);
                var maintenance            = db.Maintenances.Where(x => x.Id == entityId).FirstOrDefault();
                var type                   = db.HistoryTypes.FirstOrDefault(x => x.Title == entityType);
                MaintenanceHistory history = new MaintenanceHistory()
                {
                    Date        = DateTime.Now,
                    Maintenance = maintenance,
                    Commentary  = noteText
                };
                db.MaintenanceHistory.Add(history);
                await db.SaveChangesAsync();

                if (controllerId == "Equipment")
                {
                    return(RedirectToAction("Details", "Equipment", new { id = equipmentId }));
                }
                else
                {
                    return(RedirectToAction("Details", controllerId, new { id = entityId }));
                }
            }
            catch
            {
                return(RedirectToAction("Index", "Equipment"));
            }
        }
        //[HttpPost]
        //[ValidateAntiForgeryToken]
        //public async Task<ActionResult> UploadImg(int equipmentId, int maintenanceId, string controllerId, IFormFileCollection imgfilepath)
        //{
        //    try
        //    {
        //        int added = 0;
        //        string addedimages = "Scans added: ";
        //        var maintenance = db.Maintenances.FirstOrDefault(x => x.Id == maintenanceId);
        //        foreach (var uploadedFile in imgfilepath)
        //        {
        //            string imagestring = ImageHelper.ImageToBase64(uploadedFile);
        //            DocScan scan = new DocScan() { base64Image = imagestring, Maintenance = maintenance, Filename = uploadedFile.FileName };
        //            db.DocScans.Add(scan);
        //            added++;
        //            addedimages += scan.Filename + ", ";
        //        }

        //        if (added > 0)
        //        {
        //            addedimages = addedimages.Substring(0, addedimages.Length - 2);
        //            var equipment = db.Equipment.Include(x => x.Status)
        //                .FirstOrDefault(x => x.Id == equipmentId);
        //            var type = db.HistoryTypes.FirstOrDefault(x => x.Type == "Maintenance");
        //            History history = new History()
        //            {
        //                Date = DateTime.Now,
        //                EquipmentStatus = equipment.Status.Title,
        //                Type = type,
        //                EntityID = maintenance.Id,
        //                Equipment = equipment,
        //                Commentary = addedimages
        //            };
        //            db.History.Add(history);
        //        }

        //        await db.SaveChangesAsync();
        //        if (controllerId == "Equipment")
        //        {
        //            return RedirectToAction("Details", "Equipment", new { id = equipmentId });
        //        }
        //        else
        //        {
        //            return RedirectToAction("Details", "Maintenance", new { id = maintenanceId });
        //        }
        //    }
        //    catch
        //    {
        //        return RedirectToAction("Index", "Maintenance");
        //    }
        //}

        public IActionResult MaintenanceChangeStatus(int equipmentId, int maintenanceId, string controllerId)
        {
            try
            {
                var equipment   = db.Equipment.FirstOrDefault(x => x.Id == equipmentId);
                var status      = db.EquipmentStatuses.FirstOrDefault(x => x.Title == "SP");
                var maintenance = db.Maintenances.FirstOrDefault(x => x.Id == maintenanceId);
                equipment.Status = status;

                MaintenanceHistory history = new MaintenanceHistory()
                {
                    Date        = DateTime.Now,
                    Maintenance = maintenance,
                    Message     = "Status changed (Need Repairs)"
                };
                db.MaintenanceHistory.Add(history);

                db.SaveChanges();

                if (controllerId == "Equipment")
                {
                    return(RedirectToAction("Details", "Equipment", new { id = equipmentId }));
                }
                else
                {
                    return(RedirectToAction("Details", "Maintenance", new { id = maintenanceId }));
                }
            }
            catch
            {
                return(RedirectToAction("Index", "Maintenance"));
            }
        }
Пример #3
0
        //Background jobs
        //Check for maintenance
        public void MaintenanceFirstCheckUp()
        {
            int?MaintenanceCheckupStep = db.Settings.FirstOrDefault(s => s.Name == "MaintenanceStepValue").Value;

            List <InitialControlSchedule> InitialControlSchedule = db.InitialControlSchedule.Where(i => i.EnterKilometer != null)
                                                                   .GroupBy(x => x.VehicleId, (key, g) => g.OrderByDescending(e => e.EnterTime).FirstOrDefault()).ToList();
            List <MaintenanceType> MaintenanceType = db.MaintenanceType.ToList();

            foreach (var item in InitialControlSchedule)
            {
                foreach (var item2 in MaintenanceType)
                {
                    MaintenanceHistory MaintenanceHistoryFiltered = db.MaintenanceHistory.FirstOrDefault(m => m.InitialControlSchedule.VehicleId == item.VehicleId && m.MaintenanceId == item2.Id);

                    if (MaintenanceHistoryFiltered == null && item.EnterKilometer >= (item2.MaintenanceValue - MaintenanceCheckupStep))
                    {
                        MaintenanceHistory newMaintenanceHistory = new MaintenanceHistory();
                        newMaintenanceHistory.InitContId        = item.Id;
                        newMaintenanceHistory.MaintenanceId     = item2.Id;
                        newMaintenanceHistory.MaintenanceStatus = null;
                        newMaintenanceHistory.AddedDate         = DateTime.Now;
                        db.MaintenanceHistory.Add(newMaintenanceHistory);
                        db.SaveChanges();
                    }
                }
            }
        }
Пример #4
0
        public ActionResult DeleteConfirmed(int id)
        {
            MaintenanceHistory maintenancehistory = db.MaintenanceHistories.Find(id);

            db.MaintenanceHistories.Remove(maintenancehistory);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #5
0
 public ActionResult Edit([Bind(Include = "ID,Comment,Price,Date")] MaintenanceHistory maintenancehistory)
 {
     if (ModelState.IsValid)
     {
         db.Entry(maintenancehistory).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ID = new SelectList(db.Instruments, "ID", "ReadableID", maintenancehistory.ID);
     return(View(maintenancehistory));
 }
        public IActionResult Delete(MaintenanceHistory maintenanceHistory)
        {
            var result = _maintenanceHistoryService.Delete(maintenanceHistory);

            if (result.Success)
            {
                return(Ok(result.Message));
            }

            return(BadRequest(result.Message));
        }
Пример #7
0
        // GET: /MaintenanceHistory/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            MaintenanceHistory maintenancehistory = db.MaintenanceHistories.Find(id);

            if (maintenancehistory == null)
            {
                return(HttpNotFound());
            }
            return(View(maintenancehistory));
        }
Пример #8
0
        // GET: /MaintenanceHistory/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            MaintenanceHistory maintenancehistory = db.MaintenanceHistories.Find(id);

            if (maintenancehistory == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ID = new SelectList(db.Instruments, "ID", "ReadableID", maintenancehistory.ID);
            return(View(maintenancehistory));
        }
        public async Task <ActionResult> CloseMaintenance(int equipmentId, int maintenanceId, string controllerId, string equipmentStatus, string operatingTime, string operatingTimeMin)
        {
            try
            {
                var equipment = db.Equipment.Include(x => x.Status)
                                .FirstOrDefault(x => x.Id == equipmentId);
                equipment.Status = db.EquipmentStatuses.FirstOrDefault(x => x.Title == equipmentStatus);

                if (equipment.Status.Title == "RFU")
                {
                    equipment.OperatingTime = int.Parse(operatingTime) * 60;
                    equipment.WarningTime   = int.Parse(operatingTimeMin) * 60;
                }
                else
                {
                    equipment.OperatingTime = 0;
                    equipment.WarningTime   = 0;
                }

                var maintenance = db.Maintenances.FirstOrDefault(x => x.Id == maintenanceId);
                maintenance.IsOpened   = false;
                maintenance.FinishDate = DateTime.Now;

                MaintenanceHistory history = new MaintenanceHistory()
                {
                    Date        = DateTime.Now,
                    Maintenance = maintenance,
                    Message     = "Maintenance finished"
                };
                db.MaintenanceHistory.Add(history);

                await db.SaveChangesAsync();

                if (controllerId == "Equipment")
                {
                    return(RedirectToAction("Details", "Equipment", new { id = equipmentId }));
                }
                else
                {
                    return(RedirectToAction("Details", controllerId, new { id = maintenanceId }));
                }
            }
            catch
            {
                return(RedirectToAction("Index", "Equipment"));
            }
        }
Пример #10
0
            public SqlCommand InsertCmd(Employee employee, Aircraft aircraft = null)
            {
                string regNumber = notAssignedText;
                int    hours     = 0;

                if (aircraft != null)
                {
                    regNumber = aircraft.RegNumber;
                    hours     = (int)aircraft.FlyHours;
                }

                string text = string.Empty;

                text = String.Format("INSERT INTO {0} VALUES('{1}',EncryptByPassPhrase('12','{2}'),'{3}');",
                                     SqlMidlandsFly.Instance.Table_Employees.Name,
                                     MathExt.IntToFixedString((int)employee.Id, Employee.IdLength),
                                     employee.Name,
                                     employee.EmployeeType.ToString());
                if (employee.EmployeeType == EmployeeType.Cabin_Crew ||
                    employee.EmployeeType == EmployeeType.Flight_Deck)
                {
                    text += String.Format("INSERT INTO {0} VALUES('{1}',{2});",
                                          SqlMidlandsFly.Instance.Table_FlightHours.Name,
                                          MathExt.IntToFixedString((int)employee.Id, Employee.IdLength),
                                          hours);
                    text += String.Format("INSERT INTO {0} VALUES('{1}','{2}');",
                                          SqlMidlandsFly.Instance.Table_Assignment.Name,
                                          MathExt.IntToFixedString((int)employee.Id, Employee.IdLength),
                                          regNumber);
                }
                if (employee.EmployeeType == EmployeeType.Ground_Crew)
                {
                    for (int m = 0; m <= random.Next(1, 3); m++)
                    {
                        Instance.AddMaintenance(employee.Id, MaintenanceHistory.GenerateRandomDescription(), regNumber);
                    }
                    text += String.Format("INSERT INTO {0} VALUES('{1}','{2}');",
                                          SqlMidlandsFly.Instance.Table_Assignment.Name,
                                          MathExt.IntToFixedString((int)employee.Id, Employee.IdLength),
                                          notAssignedText);
                }
                return(new SqlCommand(text));
            }
Пример #11
0
        //End of background jobs

        //Check for maintenance history and create requisitioin
        public void CheckForMaintenanceHistoryAndCreateRequisition(int?VehicleId, CheckUpCard CheckUp, JobCards jobCard)
        {
            //Check for maintenance
            MaintenanceHistory maintenanceHistory = db.MaintenanceHistory.FirstOrDefault(m => m.MaintenanceStatus == null && m.JobCardId == null && m.InitialControlSchedule.VehicleId == VehicleId);

            if (maintenanceHistory != null)
            {
                CheckUp.MaintenanceTypeId = maintenanceHistory.MaintenanceId;
                jobCard.IsMaintenance     = true;

                //Updating Maintenance history
                MaintenanceHistory newMaintenanceHistory = db.MaintenanceHistory.Find(maintenanceHistory.Id);
                newMaintenanceHistory.JobCardId = jobCard.Id;
                if (ModelState.IsValid)
                {
                    db.Entry(newMaintenanceHistory).State = EntityState.Modified;
                }

                //Create Requisition
                int?brandId = db.Vehicles.Find(VehicleId).BrandId;
                List <WarehouseToMaintenance> warehouseToMaintenances = db.WarehouseToMaintenance.Where(w => w.MaintenanceTypeId == maintenanceHistory.MaintenanceId && w.TempWarehouse.VehicleId == brandId).ToList();

                foreach (var item in warehouseToMaintenances)
                {
                    //If it is includes to the range(if true) must not erquire SP else require
                    if (!CheckForSparePartIfMustAdd(VehicleId, item.NotRequireSPLimit, item.WarehouseId))
                    {
                        Requisitions requisition = new Requisitions();
                        requisition.IsOpen           = true;
                        requisition.JobCardId        = jobCard.Id;
                        requisition.TempWarehouseId  = item.WarehouseId;
                        requisition.RequiredQuantity = item.Quantity;
                        requisition.AddedDate        = DateTime.Now;

                        db.Requisitions.Add(requisition);
                        db.SaveChanges();
                    }
                }
            }
        }
        public async Task <ActionResult> SetMaintenanceDueDate(int equipmentId, int maintenanceId, string controllerId, string dueDate)
        {
            try
            {
                var equipment = db.Equipment.Include(x => x.Status)
                                .FirstOrDefault(x => x.Id == equipmentId);
                var maintenance = db.Maintenances.FirstOrDefault(x => x.Id == maintenanceId);

                string[] date    = dueDate.Split('-');
                DateTime setDate = new DateTime(int.Parse(date[0]), int.Parse(date[1]), int.Parse(date[2]));
                maintenance.EstimateDate = setDate;

                MaintenanceHistory history = new MaintenanceHistory()
                {
                    Date        = DateTime.Now,
                    Maintenance = maintenance,
                    Message     = "Maintenance Due Date set: " + maintenance.EstimateDate.Date
                };
                db.MaintenanceHistory.Add(history);

                await db.SaveChangesAsync();

                if (controllerId == "Equipment")
                {
                    return(RedirectToAction("Details", "Equipment", new { id = equipmentId }));
                }
                else
                {
                    return(RedirectToAction("Details", controllerId, new { id = maintenanceId }));
                }
            }
            catch
            {
                return(RedirectToAction("Index", "Equipment"));
            }
        }
Пример #13
0
        public ResponseViewModel Add(MaintenanceHistoryDto maintenanceHistoryDto)
        {
            var response = new ResponseViewModel();

            var maintenanceId = IsMaintenanceHave(maintenanceHistoryDto.MaintenanceId);

            if (!maintenanceId)
            {
                response.IsSuccess = false;
                response.Message   = "MaintenanceId Maintenance tablosunda bulunamadı";

                return(response);
            }

            var actionTypeId = IsActionTypeHave(maintenanceHistoryDto.ActionTypeId);

            if (!actionTypeId)
            {
                response.IsSuccess = false;
                response.Message   = "actionTypeId ActionType tablosunda bulunamadı";

                return(response);
            }
            if (maintenanceHistoryDto.CreatedBy != null)
            {
                var createdBy = IsUserHave((int)maintenanceHistoryDto.CreatedBy);
                if (!createdBy)
                {
                    response.IsSuccess = false;
                    response.Message   = "createdBy User tablosunda bulunamadı";

                    return(response);
                }
            }

            if (maintenanceHistoryDto.ModifiedBy != null)
            {
                var modifiedBy = IsUserHave((int)maintenanceHistoryDto.ModifiedBy);
                if (!modifiedBy)
                {
                    response.IsSuccess = false;
                    response.Message   = "modifiedBy User tablosunda bulunamadı";

                    return(response);
                }
            }

            var maintenanceHistory = new MaintenanceHistory()
            {
                MaintenanceId = maintenanceHistoryDto.MaintenanceId,
                ActionTypeId  = maintenanceHistoryDto.ActionTypeId,
                CreateDate    = DateTime.Now,
                CreatedBy     = maintenanceHistoryDto.CreatedBy,
                ModifyDate    = maintenanceHistoryDto.ModifyDate,
                ModifiedBy    = maintenanceHistoryDto.ModifiedBy,
                Text          = maintenanceHistoryDto.Text,
            };

            _maintenanceHistoryDal.Add(maintenanceHistory);

            var saving = _maintenanceHistoryDal.SaveChanges();

            if (!saving)
            {
                response.IsSuccess = false;
                response.Message   = "MaintenanceHistory ekleme işlemi sırasında hata oluştu.";

                return(response);
            }

            response.Data = "Id : " + maintenanceHistory.Id;

            return(response);
        }
Пример #14
0
 public IResult Update(MaintenanceHistory maintenanceHistory)
 {
     _maintenanceHistoryDal.Update(maintenanceHistory);
     return(new SuccessResult(Messages.Updated));
 }
Пример #15
0
 public IResult Add(MaintenanceHistory maintenanceHistory)
 {
     _maintenanceHistoryDal.Add(maintenanceHistory);
     return(new SuccessResult(Messages.Added));
 }