/// <summary>
        /// Deletes the asynchronous.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public async Task<SaveResult> DeleteAsync(FARInitialTargetLogDto entity)
        {
            SaveResult result = SaveResult.FAILURE;

            try
            {
                using (FailureAnalysisEntities context = new FailureAnalysisEntities())
                {
                    var assembly = context.LOG_FARInitialTarget.Single(x => x.Id == entity.Id && x.IsDeleted == false);
                    assembly.IsDeleted = true;

                    context.Entry<LOG_FARInitialTarget>(assembly).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(FARInitialTargetLogDto entity)
        {
            SaveResult result = SaveResult.FAILURE;
            try
            {
                using (FailureAnalysisEntities context = new FailureAnalysisEntities())
                {
                    LOG_FARInitialTarget add = context.LOG_FARInitialTarget.Create();

                    add.TargetDate = entity.TargetDate;
                    add.ReasonId = entity.ReasonId;
                    add.MasterId = entity.MasterId;
                    add.IsDeleted = false;
                    add.LastUpdatedBy = entity.LastUpdatedBy;
                    add.LastUpdate = DateTime.Now;

                    context.Entry<LOG_FARInitialTarget>(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;
        }
示例#3
0
        public async Task<JsonResult> AnaEditFA(int id, string btnSubmit, AnaRequestViewModel viewmodel)
        {
            var master = await MasterRepository.SingleAsync(id);

            if (btnSubmit == "Release")
            {
                master.StatusId = (int)StatusType.ONGOING;
                var update = MasterRepository.Update(master);
                if (update == Model.SaveResult.SUCCESS)
                {
                    Response.StatusCode = (int)HttpStatusCode.OK;
                    return new JsonResult
                    {
                        JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                        Data = new { code = "RL01" }
                    };
                }
                else
                {
                    Response.StatusCode = (int)HttpStatusCode.BadRequest;
                    return new JsonResult
                    {
                        JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                        Data = new { code = "RL02" }
                    };
                }
            }

            if (master != null)
            {
                if (viewmodel.InitialReportTargetDate != master.InitialReportTargetDate)
                {
                    //Write log
                    FARInitialTargetLogDto logIni = new FARInitialTargetLogDto
                    {
                        MasterId = id,
                        ReasonId = viewmodel.InitialReasonId,
                        TargetDate = viewmodel.InitialReportTargetDate,
                        LastUpdatedBy = this.CurrentName,
                    };
                    InitialTargetLogRepository.Add(logIni);
                }

                if (viewmodel.FinalReportTargetDate != master.FinalReportTargetDate)
                {
                    //Write log
                    FARFinalTargetLogDto logFinal = new FARFinalTargetLogDto
                    {
                        MasterId = id,
                        ReasonId = viewmodel.FinalReasonId,
                        TargetDate = viewmodel.FinalReportTargetDate,
                        LastUpdatedBy = this.CurrentName,
                    };
                    FinalTargetLogRepository.Add(logFinal);
                }
                master.SamplesArriveDate = viewmodel.SamplesArriveDate;
                var reportType = ReportTypesRepository.GetAll();
                if (viewmodel.InitialReportTargetDate == null)
                    master.InitialReportTargetDate = viewmodel.SamplesArriveDate.Value.AddDays(reportType.Single(x => x.Id == (int)ReportType.INITIAL).DaysAfter);
                else
                    master.InitialReportTargetDate = viewmodel.InitialReportTargetDate;
                if (viewmodel.FinalReportTargetDate == null)
                    master.FinalReportTargetDate = viewmodel.SamplesArriveDate.Value.AddDays(reportType.Single(x => x.Id == (int)ReportType.FINAL).DaysAfter);
                else
                    master.FinalReportTargetDate = viewmodel.FinalReportTargetDate;
                master.LastUpdatedBy = this.CurrentName;

                var result = await MasterRepository.UpdateAsync(master);
                if (result == Model.SaveResult.SUCCESS)
                {
                    Response.StatusCode = (int)HttpStatusCode.OK;
                    return new JsonResult
                    {
                        JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                        Data = new
                        {
                            code = "ED01",
                            initialDate = master.InitialReportTargetDate.HasValue ? master.InitialReportTargetDate.Value.ToString("MM/dd/yyyy") : "",
                            finalDate = master.FinalReportTargetDate.HasValue ? master.FinalReportTargetDate.Value.ToString("MM/dd/yyyy") : ""
                        }
                    };
                }
            }
            Response.StatusCode = (int)HttpStatusCode.BadRequest;
            return new JsonResult
            {
                JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                Data = new { code = "ED02" }
            };
        }
        /// <summary>
        /// Updates the asynchronous.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public async Task<SaveResult> UpdateAsync(FARInitialTargetLogDto entity)
        {
            SaveResult result = SaveResult.FAILURE;

            try
            {
                using (FailureAnalysisEntities context = new FailureAnalysisEntities())
                {
                    var log = context.LOG_FARInitialTarget.Single(x => x.Id == entity.Id && x.IsDeleted == false);

                    log.MasterId = entity.MasterId;
                    log.ReasonId = entity.ReasonId;
                    log.IsDeleted = entity.IsDeleted;
                    log.TargetDate = entity.TargetDate;
                    log.LastUpdatedBy = entity.LastUpdatedBy;
                    log.LastUpdate = DateTime.Now;

                    context.Entry<LOG_FARInitialTarget>(log).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;
        }
示例#5
0
        public async Task<JsonResult> ManEditFA(int id, ManRequestViewModel request)
        {
            var master = await MasterRepository.SingleAsync(id);
            string oldAnalyst = master.Analyst;

            if (master != null)
            {
                string currentName = this.CurrentName;
                if (master.PriorityId != request.PriorityId)
                {
                    FARPriorityLogDto logPriority = new FARPriorityLogDto
                    {
                        MasterId = id,
                        PriorityIdOld = master.PriorityId,
                        PriorityIdNew = request.PriorityId,
                        ReasonId = request.ReasonId,
                        LastUpdatedBy = currentName,
                        IsDeleted = false,
                    };
                    //Log Priority
                    PriorityLogRepository.Add(logPriority);
                }
                var user = UserRepository.Single(request.UserId);
                if (user != null)
                {
                    master.Analyst = user.Email;
                }
                master.PriorityId = request.PriorityId;
                master.LastUpdatedBy = currentName;
                master.StatusId = (int)request.StatusId;
                master.SamplesArriveDate = request.SamplesArriveDate;

                if (request.InitialReportTargetDate != master.InitialReportTargetDate)
                {
                    //Write log
                    FARInitialTargetLogDto logIni = new FARInitialTargetLogDto
                    {
                        MasterId = id,
                        ReasonId = request.InitialReasonId,
                        TargetDate = request.InitialReportTargetDate,
                        LastUpdatedBy = this.CurrentName,
                    };
                    InitialTargetLogRepository.Add(logIni);
                }

                if (request.FinalReportTargetDate != master.FinalReportTargetDate)
                {
                    //Write log
                    FARFinalTargetLogDto logFinal = new FARFinalTargetLogDto
                    {
                        MasterId = id,
                        ReasonId = request.FinalReasonId,
                        TargetDate = request.FinalReportTargetDate,
                        LastUpdatedBy = this.CurrentName,
                    };
                    FinalTargetLogRepository.Add(logFinal);
                }
                if (request.SamplesArriveDate.HasValue)
                {
                    var reportType = ReportTypesRepository.GetAll();
                    if (request.InitialReportTargetDate == null)
                        master.InitialReportTargetDate = request.SamplesArriveDate.Value.AddDays(reportType.Single(x => x.Id == (int)ReportType.INITIAL).DaysAfter);
                    else
                        master.InitialReportTargetDate = request.InitialReportTargetDate;
                    if (request.FinalReportTargetDate == null)
                        master.FinalReportTargetDate = request.SamplesArriveDate.Value.AddDays(reportType.Single(x => x.Id == (int)ReportType.FINAL).DaysAfter);
                    else
                        master.FinalReportTargetDate = request.FinalReportTargetDate;
                }

                var result = await MasterRepository.UpdateAsync(master);
                if (result == Model.SaveResult.SUCCESS)
                {
                    Response.StatusCode = (int)HttpStatusCode.OK;
                    if (oldAnalyst != master.Analyst)
                    {
                        //Add Analyst Reassign Log
                        FARAnalystReassignLogDto analystReassign = new FARAnalystReassignLogDto
                        {
                            MasterId = id,
                            AnalystFrom = oldAnalyst,
                            AnalystTo = master.Analyst,
                            LastUpdatedBy = currentName,
                        };

                        //Log Analyst reassign
                        AnalystReassignLogRepository.Add(analystReassign);
                        //SendMail
                        string emailSubject = "FA Request " + request.FARNumber + " has been assigned to you";
                        string ebody = "You have been assigned by " + currentName + " to oversee FA Number: " + request.FARNumber + ". Please login to FA DB to update its details.";
                        string emailBody = string.Format("{0}<br><br>{1}", ebody, DateTime.Now.ToShortDateString());
                        try
                        {
                            Mail.Send(master.Analyst, emailSubject, ebody);
                        }
                        catch (Exception ex)
                        {
                            LogService.Error(ex.Message, ex);
                        }
                    }

                    return new JsonResult
                    {
                        JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                        Data = new
                        {
                            code = "ED01",
                            initialDate = master.InitialReportTargetDate.HasValue ? master.InitialReportTargetDate.Value.ToString("MM/dd/yyyy") : "",
                            finalDate = master.FinalReportTargetDate.HasValue ? master.FinalReportTargetDate.Value.ToString("MM/dd/yyyy") : ""
                        }
                    };
                }
            }
            Response.StatusCode = (int)HttpStatusCode.BadRequest;
            return new JsonResult
            {
                JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                Data = new { code = "ED02" }
            };
        }