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

            try
            {
                using (FailureAnalysisEntities context = new FailureAnalysisEntities())
                {
                    var reassign = context.LOG_FARAnalystReassign.Single(x => x.Id == entity.Id && x.IsDeleted == false);
                    reassign.IsDeleted = true;
                    reassign.LastUpdate = DateTime.Now;
                    reassign.LastUpdatedBy = entity.LastUpdatedBy;

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

                    add.MasterId = entity.MasterId;
                    add.AnalystFrom = entity.AnalystFrom;
                    add.AnalystTo = entity.AnalystTo;
                    add.IsDeleted = entity.IsDeleted;
                    add.LastUpdatedBy = entity.LastUpdatedBy;
                    add.LastUpdate = DateTime.Now;

                    context.Entry<LOG_FARAnalystReassign>(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>
        /// Deletes the specified entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public SaveResult Delete(FARAnalystReassignLogDto entity)
        {
            SaveResult result = SaveResult.FAILURE;

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

                    context.Entry<LOG_FARAnalystReassign>(assembly).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;
        }
Ejemplo n.º 4
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" }
            };
        }