public JsonResult ConfirmAddProcess(int deviceId, ProcessViewModel viewmodel) { FARProcessHistoryDto his = new FARProcessHistoryDto() { DeviceId = deviceId, Analystor = viewmodel.Email, Comment = viewmodel.Comment, ProcessTypeId = viewmodel.ProcessTypeId, LastUpdatedBy = this.CurrentName, IsIncluded = true, SeqNum = 0, }; var result = ProcessHisRep.Add(his); switch (result) { case Model.SaveResult.SUCCESS: Response.StatusCode = (int)HttpStatusCode.OK; return new JsonResult { Data = new { code = "SB01", Id = deviceId }, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; case Model.SaveResult.FAILURE: Response.StatusCode = (int)HttpStatusCode.BadRequest; return new JsonResult { Data = new { code = "SB02", Id = deviceId }, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; } Response.StatusCode = (int)HttpStatusCode.BadRequest; return new JsonResult { Data = new { code = "SB02", Id = deviceId }, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; }
/// <summary> /// Checks the exist photo. /// </summary> /// <param name="item">The item.</param> /// <returns></returns> private bool CheckExistPhoto(FARProcessHistoryDto item) { string master = item.Device.MasterId.ToString().PadLeft(10, '0'); string device = item.DeviceId.ToString().PadLeft(10, '0'); string process = item.Id.ToString().PadLeft(10, '0'); string folderProcess = System.IO.Path.Combine(Server.MapPath("~/Upload"), master, "DEVICE", device, process); if (System.IO.Directory.Exists(folderProcess)) { //Get all files string[] files = System.IO.Directory.GetFiles(folderProcess); if (files.Length > 0) return true; } return false; }
/// <summary> /// Loads the processes. /// </summary> /// <param name="idDevice">The identifier.</param> /// <returns></returns> private async Task<Model.SaveResult> AddProcess(int idDevice, string product, bool isInclude) { //insert all records from Process Types var proTypes = (await ProcessTypesRepository.GetAllAsync()).OrderBy(q => q.SeqNumber); List<FARProcessHistoryDto> lstProcess = new List<FARProcessHistoryDto>(); foreach (var item in proTypes) { var fph = new FARProcessHistoryDto(); var pp = ProProRes.FindBy(item.Id, product); if (pp != null) fph.Analystor = pp.InChargePerson; else fph.Analystor = ""; fph.DeviceId = idDevice; fph.ProcessTypeId = item.Id; fph.Description = item.Description; fph.SeqNum = item.SeqNumber ?? 0; fph.IsDeleted = false; fph.LastUpdatedBy = this.CurrentName; fph.IsIncluded = isInclude; lstProcess.Add(fph); } return await ProcessHisRep.AddRangeAsync(lstProcess); }
/// <summary> /// Deletes the asynchronous. /// </summary> /// <param name="entity">The entity.</param> /// <returns></returns> public async Task<SaveResult> DeleteAsync(FARProcessHistoryDto entity) { SaveResult result = SaveResult.FAILURE; try { using (FailureAnalysisEntities context = new FailureAnalysisEntities()) { var history = context.FAR_ProcessHistory.Single(x => x.Id == entity.Id && x.IsDeleted == false); history.IsDeleted = true; history.LastUpdate = DateTime.Now; history.LastUpdatedBy = entity.LastUpdatedBy; context.Entry<FAR_ProcessHistory>(history).State = System.Data.Entity.EntityState.Modified; result = await context.SaveChangesAsync() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE; } } catch (Exception ex) { _logService.Error(ex.Message, ex); result = SaveResult.FAILURE; } return result; }
/// <summary> /// Adds the asynchronous. /// </summary> /// <param name="entity">The entity.</param> /// <returns></returns> public async Task<SaveResult> AddAsync(FARProcessHistoryDto entity) { SaveResult result = SaveResult.FAILURE; try { using (FailureAnalysisEntities context = new FailureAnalysisEntities()) { FAR_ProcessHistory add = context.FAR_ProcessHistory.Create(); add.DeviceId = entity.DeviceId; add.ProcessResultId = entity.ProcessResultId; add.ProcessTypeId = entity.ProcessTypeId; add.Description = entity.Description; add.SeqNum = entity.SeqNum; add.Iteration = entity.Iteration; add.Analystor = entity.Analystor; add.Comment = entity.Comment; add.PlannedIN = entity.PlannedIn; add.PlannedOUT = entity.PlannedOut; add.DateIn = entity.DateIn; add.DateOut = entity.DateOut; add.IsIncluded = entity.IsIncluded; add.IsDeleted = entity.IsDeleted; add.LastUpdate = DateTime.Now; add.LastUpdatedBy = entity.LastUpdatedBy; context.Entry<FAR_ProcessHistory>(add).State = System.Data.Entity.EntityState.Added; result = await context.SaveChangesAsync() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE; } } catch (Exception ex) { _logService.Error(ex.Message, ex); result = SaveResult.FAILURE; } return result; }
/// <summary> /// Edits the process. /// </summary> /// <param name="entity">The entity.</param> /// <returns></returns> public SaveResult EditProcess(FARProcessHistoryDto entity) { SaveResult result = SaveResult.FAILURE; try { using (FailureAnalysisEntities context = new FailureAnalysisEntities()) { var updated = context.FAR_ProcessHistory.Single(x => x.Id == entity.Id && x.IsDeleted == false); updated.ProcessTypeId = entity.ProcessTypeId; updated.Analystor = entity.Analystor; updated.Comment = entity.Comment; updated.LastUpdate = DateTime.Now; updated.LastUpdatedBy = entity.LastUpdatedBy; context.Entry<FAR_ProcessHistory>(updated).State = System.Data.Entity.EntityState.Modified; result = context.SaveChanges() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE; } } catch (Exception ex) { _logService.Error(ex.Message, ex); result = SaveResult.FAILURE; } return result; }
/// <summary> /// Updates the asynchronous. /// </summary> /// <param name="entity">The entity.</param> /// <returns></returns> public async Task<SaveResult> UpdateAsync(FARProcessHistoryDto entity) { SaveResult result = SaveResult.FAILURE; try { using (FailureAnalysisEntities context = new FailureAnalysisEntities()) { var update = context.FAR_ProcessHistory.Single(x => x.Id == entity.Id && x.IsDeleted == false); update.DeviceId = entity.DeviceId; update.ProcessResultId = entity.ProcessResultId; update.ProcessTypeId = entity.ProcessTypeId; update.Description = entity.Description; update.SeqNum = entity.SeqNum; update.Iteration = entity.Iteration; update.Analystor = entity.Analystor; update.Comment = entity.Comment; update.PlannedOUT = entity.PlannedOut; update.PlannedIN = entity.PlannedIn; update.DateIn = entity.DateIn; update.DateOut = entity.DateOut; update.IsIncluded = entity.IsIncluded; update.IsDeleted = entity.IsDeleted; update.LastUpdate = DateTime.Now; update.LastUpdatedBy = entity.LastUpdatedBy; context.Entry<FAR_ProcessHistory>(update).State = System.Data.Entity.EntityState.Modified; result = await context.SaveChangesAsync() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE; } } catch (Exception ex) { _logService.Error(ex.Message, ex); result = SaveResult.FAILURE; } return result; }