/// <summary>
        /// Adds the specified entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public SaveResult Add(MSTProductDto entity)
        {
            SaveResult result = SaveResult.FAILURE;
            try
            {
                using (FailureAnalysisEntities context = new FailureAnalysisEntities())
                {
                    MST_Product add = context.MST_Product.Create();

                    add.Description = entity.Description;
                    add.MainPerson = entity.MainPerson;
                    add.SecondaryPerson = entity.SecondaryPerson;
                    add.TertiaryPerson = entity.TertiaryPerson;
                    add.LabSiteId = entity.LabSiteId;
                    add.IsDeleted = false;
                    add.Name = entity.Name;
                    add.LastUpdatedBy = entity.LastUpdatedBy;
                    add.LastUpdate = DateTime.Now;

                    context.Entry<MST_Product>(add).State = System.Data.Entity.EntityState.Added;
                    result = context.SaveChanges() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE;
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                result = SaveResult.FAILURE;
            }
            return result;
        }
        /// <summary>
        /// Adds the range.
        /// </summary>
        /// <param name="entities">The entities.</param>
        /// <returns></returns>
        public SaveResult AddRange(IEnumerable<FARInitialTargetLogDto> entities)
        {
            SaveResult result = SaveResult.FAILURE;
            try
            {
                using (FailureAnalysisEntities context = new FailureAnalysisEntities())
                {
                    LOG_FARInitialTarget add = null;
                    foreach (var entity in entities)
                    {
                        add = context.LOG_FARInitialTarget.Create();

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

                        context.Entry<LOG_FARInitialTarget>(add).State = System.Data.Entity.EntityState.Added;
                    }
                    result = context.SaveChanges() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE;
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                result = SaveResult.FAILURE;
            }
            return result;
        }
        /// <summary>
        /// Adds the range.
        /// </summary>
        /// <param name="entities">The entities.</param>
        /// <returns></returns>
        public SaveResult AddRange(IEnumerable<MSTServiceDto> entities)
        {
            SaveResult result = SaveResult.FAILURE;
            try
            {
                using (FailureAnalysisEntities context = new FailureAnalysisEntities())
                {
                    MST_Services add = null;
                    foreach (var entity in entities)
                    {
                        add = context.MST_Services.Create();

                        add.Description = entity.Description;
                        add.IsDeleted = false;
                        add.Name = entity.Name;
                        add.LastUpdatedBy = entity.LastUpdatedBy;
                        add.LastUpdate = DateTime.Now;

                        context.Entry<MST_Services>(add).State = System.Data.Entity.EntityState.Added;
                    }
                    result = context.SaveChanges() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE;
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                result = SaveResult.FAILURE;
            }
            return result;
        }
        /// <summary>
        /// Deletes the by.
        /// </summary>
        /// <param name="Id">The identifier.</param>
        /// <returns></returns>
        public SaveResult DeleteBy(int Id)
        {
            SaveResult result = SaveResult.FAILURE;

            try
            {
                using (FailureAnalysisEntities context = new FailureAnalysisEntities())
                {
                    var assembly = context.LOG_FARUpload.Single(x => x.Id == Id);

                    context.Entry<LOG_FARUpload>(assembly).State = System.Data.Entity.EntityState.Deleted;
                    result = context.SaveChanges() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE;
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                result = SaveResult.FAILURE;
            }

            return result;
        }
        /// <summary>
        /// Adds the specified entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public SaveResult Add(DelayReasonDto entity)
        {
            SaveResult result = SaveResult.FAILURE;
            try
            {
                using (FailureAnalysisEntities context = new FailureAnalysisEntities())
                {
                    MST_ReasonINIReport add = context.MST_ReasonINIReport.Create();

                    add.Description = entity.Description;
                    add.IsDeleted = entity.IsDeleted;
                    add.LastUpdatedBy = entity.LastUpdatedBy;
                    add.LastUpdate = DateTime.Now;

                    context.Entry<MST_ReasonINIReport>(add).State = System.Data.Entity.EntityState.Added;
                    result = context.SaveChanges() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE;
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                result = SaveResult.FAILURE;
            }
            return result;
        }
        /// <summary>
        /// Adds the range.
        /// </summary>
        /// <param name="entities">The entities.</param>
        /// <returns></returns>
        public SaveResult AddRange(IEnumerable<RecordLockDto> entities)
        {
            SaveResult result = SaveResult.FAILURE;
            try
            {
                using (FailureAnalysisEntities context = new FailureAnalysisEntities())
                {
                    foreach (var entity in entities)
                    {
                        FAR_RecordLock add = context.FAR_RecordLock.Create();

                        add.ProcessHistoryId = entity.ProcessHistoryId;
                        add.LockBy = entity.LockBy;
                        add.LockDate = entity.LockDate;
                        add.MasterId = entity.MasterId;
                        add.ReleaseDate = entity.ReleaseDate;
                        add.LastUpdatedBy = entity.LastUpdatedBy;
                        add.LastUpdate = DateTime.Now;

                        context.Entry<FAR_RecordLock>(add).State = System.Data.Entity.EntityState.Added;
                    }
                    result = context.SaveChanges() > 0 ? SaveResult.SUCESS : SaveResult.FAILURE;
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                result = SaveResult.FAILURE;
            }
            return result;
        }
        /// <summary>
        /// Updates the specified entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public SaveResult Update(FARUploadDto entity)
        {
            SaveResult result = SaveResult.FAILURE;

            try
            {
                using (FailureAnalysisEntities context = new FailureAnalysisEntities())
                {
                    var upload = context.LOG_FARUpload.Single(x => x.Id == entity.Id);

                    upload.FileName = entity.FileName;
                    upload.MasterId = entity.MasterId;
                    upload.ReasonId = entity.ReasonId;
                    upload.FAType = entity.FAType;
                    upload.UploadedBy = entity.UploadedBy;
                    upload.UploadedDate = DateTime.Now;

                    context.Entry<LOG_FARUpload>(upload).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>
        /// Adds the specified entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public SaveResult Add(MSTProcessTypesDto entity)
        {
            SaveResult result = SaveResult.FAILURE;
            try
            {
                using (FailureAnalysisEntities context = new FailureAnalysisEntities())
                {
                    MST_ProcessTypes add = context.MST_ProcessTypes.Create();

                    add.Description = entity.Description;
                    add.IsDeleted = false;
                    add.Name = entity.Name;
                    add.SeqNumber = entity.SeqNumber;
                    add.Duration = entity.Duration;
                    add.LastUpdatedBy = entity.LastUpdatedBy;
                    add.LastUpdate = DateTime.Now;

                    context.Entry<MST_ProcessTypes>(add).State = System.Data.Entity.EntityState.Added;
                    result = context.SaveChanges() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE;
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                result = SaveResult.FAILURE;
            }
            return result;
        }
        /// <summary>
        /// Deletes the by.
        /// </summary>
        /// <param name="Id">The identifier.</param>
        /// <returns></returns>
        public SaveResult DeleteBy(int Id)
        {
            SaveResult result = SaveResult.FAILURE;

            try
            {
                using (FailureAnalysisEntities context = new FailureAnalysisEntities())
                {
                    var failureType = context.MST_FailureType.Single(x => x.Id == Id && x.IsDeleted == false);
                    failureType.IsDeleted = true;
                    failureType.LastUpdate = DateTime.Now;

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

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

                    context.Entry<MST_FARReport>(report).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>
        /// Adds the specified entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public SaveResult Add(LOGProcessHistoryDto entity)
        {
            SaveResult result = SaveResult.FAILURE;
            try
            {
                using (FailureAnalysisEntities context = new FailureAnalysisEntities())
                {
                    LOG_ProcessHistory add = context.LOG_ProcessHistory.Create();

                    add.ProcessHisId = entity.ProcessHisId;
                    add.InsertedBy = entity.InsertedBy;
                    add.PlanTo = entity.PlanTo;
                    add.PlanFrom = entity.PlanFrom;
                    add.PlanType = (byte)entity.PlanType;
                    add.Description = entity.Description;
                    add.InsertedDate = DateTime.Now;

                    context.Entry<LOG_ProcessHistory>(add).State = System.Data.Entity.EntityState.Added;
                    result = context.SaveChanges() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE;
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                result = SaveResult.FAILURE;
            }
            return result;
        }
        /// <summary>
        /// Updates the specified entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public SaveResult Update(MSTFarReportDto entity)
        {
            SaveResult result = SaveResult.FAILURE;

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

                    report.OriginId = entity.OriginId;
                    report.ReportTypeId = entity.ReportTypeId;
                    report.Required = entity.Required;
                    report.Description = entity.Description;
                    report.LastUpdatedBy = entity.LastUpdatedBy;
                    report.LastUpdate = DateTime.Now;

                    context.Entry<MST_FARReport>(report).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>
        /// Adds the range.
        /// </summary>
        /// <param name="entities">The entities.</param>
        /// <returns></returns>
        public SaveResult AddRange(IEnumerable<FARMasterDto> entities)
        {
            SaveResult result = SaveResult.FAILURE;
            try
            {
                using (FailureAnalysisEntities context = new FailureAnalysisEntities())
                {
                    FAR_Master add = null;
                    foreach (var entity in entities)
                    {
                        add = context.FAR_Master.Create();

                        add.Number = entity.Number;
                        add.OriginId = entity.OriginId;
                        add.Requestor = entity.Requestor;
                        add.RefNo = entity.RefNo;
                        add.FailureTypeId = entity.FailureTypeId;
                        add.FailureOriginId = entity.FailureOriginId;
                        add.FailureRate = entity.FailureRate;
                        add.StatusId = entity.StatusId;
                        add.Analyst = entity.Analyst;
                        add.RequestDate = entity.RequestDate;
                        add.SamplesArriveDate = entity.SamplesArriveDate;
                        add.PriorityId = entity.PriorityId;
                        add.InitialReportTargetDate = entity.InitialReportTargetDate;
                        add.BUId = entity.BUId;
                        add.Product = entity.Product;
                        add.FailureDesc = entity.FailureDesc;
                        add.FinalReportTargetDate = entity.FinalReportTargetDate;
                        add.Submitted = entity.Submitted;
                        add.Customer = entity.Customer;
                        add.LabSiteId = entity.LabSiteId;
                        add.RatingId = entity.RatingId;
                        add.Comments = entity.Comments;
                        add.IsDeleted = entity.IsDeleted;
                        add.LastUpdatedBy = entity.LastUpdatedBy;
                        add.LastUpdate = DateTime.Now;

                        context.Entry<FAR_Master>(add).State = System.Data.Entity.EntityState.Added;
                    }
                    result = context.SaveChanges() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE;
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                result = SaveResult.FAILURE;
            }
            return result;
        }
        /// <summary>
        /// Updates the specified entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public SaveResult Update(FARMasterDto entity)
        {
            SaveResult result = SaveResult.FAILURE;

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

                    entry.Number = entity.Number;
                    entry.OriginId = entity.OriginId;
                    entry.Requestor = entity.Requestor;
                    entry.RefNo = entity.RefNo;
                    entry.FailureTypeId = entity.FailureTypeId;
                    entry.FailureOriginId = entity.FailureOriginId;
                    entry.FailureRate = entity.FailureRate;
                    entry.StatusId = entity.StatusId;
                    entry.Analyst = entity.Analyst;
                    entry.RequestDate = entity.RequestDate;
                    entry.SamplesArriveDate = entity.SamplesArriveDate;
                    entry.PriorityId = entity.PriorityId;
                    entry.InitialReportTargetDate = entity.InitialReportTargetDate;
                    entry.BUId = entity.BUId;
                    entry.Product = entity.Product;
                    entry.FailureDesc = entity.FailureDesc;
                    entry.FinalReportTargetDate = entity.FinalReportTargetDate;
                    entry.Submitted = entity.Submitted;
                    entry.Customer = entity.Customer;
                    entry.LabSiteId = entity.LabSiteId;
                    entry.RatingId = entity.RatingId;
                    entry.Comments = entity.Comments;
                    entry.IsDeleted = entity.IsDeleted;
                    entry.LastUpdatedBy = entity.LastUpdatedBy;
                    entry.LastUpdate = DateTime.Now;

                    context.Entry<FAR_Master>(entry).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>
        /// Adds the specified entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public SaveResult Add(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 = context.SaveChanges() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE;
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                result = SaveResult.FAILURE;
            }
            return result;
        }
        /// <summary>
        /// Updates the specified entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public SaveResult Update(FARPriorityLogDto entity)
        {
            SaveResult result = SaveResult.FAILURE;

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

                    his.MasterId = entity.MasterId;
                    his.IsDeleted = entity.IsDeleted;
                    his.PriorityOld = entity.PriorityIdOld;
                    his.PriorityNew = entity.PriorityIdNew;
                    his.ReasonId = entity.ReasonId;
                    his.LastUpdatedBy = entity.LastUpdatedBy;
                    his.LastUpdate = DateTime.Now;

                    context.Entry<LOG_FARPriority>(his).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 specified entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public SaveResult Update(RecordLockDto entity)
        {
            SaveResult result = SaveResult.FAILURE;

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

                    update.ProcessHistoryId = entity.ProcessHistoryId;
                    update.LockBy = entity.LockBy;
                    update.LockDate = entity.LockDate;
                    update.MasterId = entity.MasterId;
                    update.ReleaseDate = entity.ReleaseDate;
                    update.LastUpdatedBy = entity.LastUpdatedBy;
                    update.LastUpdate = DateTime.Now;

                    context.Entry<FAR_RecordLock>(update).State = System.Data.Entity.EntityState.Modified;
                    result = context.SaveChanges() > 0 ? SaveResult.SUCESS : SaveResult.FAILURE;
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                result = SaveResult.FAILURE;
            }

            return result;
        }
        /// <summary>
        /// Adds the specified entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public SaveResult Add(FARPriorityLogDto entity)
        {
            SaveResult result = SaveResult.FAILURE;
            try
            {
                using (FailureAnalysisEntities context = new FailureAnalysisEntities())
                {
                    LOG_FARPriority add = context.LOG_FARPriority.Create();

                    add.PriorityOld = entity.PriorityIdOld;
                    add.PriorityNew = entity.PriorityIdNew;
                    add.ReasonId = entity.ReasonId;
                    add.IsDeleted = false;
                    add.MasterId = entity.MasterId;
                    add.LastUpdatedBy = entity.LastUpdatedBy;
                    add.LastUpdate = DateTime.Now;

                    context.Entry<LOG_FARPriority>(add).State = System.Data.Entity.EntityState.Added;
                    result = context.SaveChanges() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE;
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                result = SaveResult.FAILURE;
            }
            return result;
        }
        /// <summary>
        /// Deletes the by.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <returns></returns>
        public SaveResult DeleteBy(int id)
        {
            SaveResult result = SaveResult.FAILURE;

            try
            {
                using (FailureAnalysisEntities context = new FailureAnalysisEntities())
                {
                    var record = context.FAR_RecordLock.Single(x => x.Id == id && x.IsDeleted == false);
                    record.IsDeleted = true;
                    record.LastUpdate = DateTime.Now;

                    context.Entry<FAR_RecordLock>(record).State = System.Data.Entity.EntityState.Modified;
                    result = context.SaveChanges() > 0 ? SaveResult.SUCESS : 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(MSTPriorityDto entity)
        {
            SaveResult result = SaveResult.FAILURE;

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

                    context.Entry<MST_Priority>(priority).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>
        /// Adds the range.
        /// </summary>
        /// <param name="entities">The entities.</param>
        /// <returns></returns>
        public SaveResult AddRange(IEnumerable<FARUploadDto> entities)
        {
            SaveResult result = SaveResult.FAILURE;
            try
            {
                using (FailureAnalysisEntities context = new FailureAnalysisEntities())
                {
                    LOG_FARUpload add = null;
                    foreach (var entity in entities)
                    {
                        add = context.LOG_FARUpload.Create();

                        add.FileName = entity.FileName;
                        add.MasterId = entity.MasterId;
                        add.ReasonId = entity.ReasonId;
                        add.FAType = entity.FAType;
                        add.UploadedBy = entity.UploadedBy;
                        add.UploadedDate = DateTime.Now;

                        context.Entry<LOG_FARUpload>(add).State = System.Data.Entity.EntityState.Added;
                    }
                    result = context.SaveChanges() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE;
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                result = SaveResult.FAILURE;
            }
            return result;
        }
        /// <summary>
        /// Adds the specified entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public SaveResult Add(FARMechanismDto entity)
        {
            SaveResult result = SaveResult.FAILURE;
            try
            {
                using (FailureAnalysisEntities context = new FailureAnalysisEntities())
                {
                    FAR_Mechanism add = context.FAR_Mechanism.Create();

                    add.Description = entity.Description;
                    add.IsDeleted = false;
                    add.Name = entity.Name;
                    add.LastUpdatedBy = entity.LastUpdatedBy;
                    add.LastUpdate = DateTime.Now;

                    context.Entry<FAR_Mechanism>(add).State = System.Data.Entity.EntityState.Added;
                    result = context.SaveChanges() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE;
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                result = SaveResult.FAILURE;
            }
            return result;
        }
        /// <summary>
        /// Updates the specified entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public SaveResult Update(DelayReasonDto entity)
        {
            SaveResult result = SaveResult.FAILURE;

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

                    assembly.Description = entity.Description;
                    assembly.LastUpdatedBy = entity.LastUpdatedBy;
                    assembly.LastUpdate = DateTime.Now;

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

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

                    context.Entry<FAR_Mechanism>(fabSite).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 specified entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public SaveResult Update(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 = context.SaveChanges() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE;
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                result = SaveResult.FAILURE;
            }

            return result;
        }
        /// <summary>
        /// Adds the specified entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public SaveResult Add(MSTProcessProductDto entity)
        {
            SaveResult result = SaveResult.FAILURE;
            try
            {
                using (FailureAnalysisEntities context = new FailureAnalysisEntities())
                {
                    MST_ProcessProduct add = context.MST_ProcessProduct.Create();

                    //Check productId and ProcessTypeId exits record?
                    var checkExits = context.MST_ProcessProduct.Where(x => x.ProcessTypeId == entity.ProcessTypeId && x.ProductId == entity.ProductId).FirstOrDefault();
                    if (checkExits != null)
                    {
                        checkExits.InChargePerson = entity.InChargePerson;
                        checkExits.IsDeleted = false;
                        checkExits.LastUpdatedBy = entity.LastUpdatedBy;
                        checkExits.LastUpdate = DateTime.Now;

                        context.Entry<MST_ProcessProduct>(checkExits).State = System.Data.Entity.EntityState.Modified;
                    }
                    else
                    {
                        add.Description = entity.Description;
                        add.ProductId = entity.ProductId;
                        add.ProcessTypeId = entity.ProcessTypeId;
                        add.InChargePerson = entity.InChargePerson;
                        add.IsDeleted = false;
                        add.LastUpdatedBy = entity.LastUpdatedBy;
                        add.LastUpdate = DateTime.Now;

                        context.Entry<MST_ProcessProduct>(add).State = System.Data.Entity.EntityState.Added;
                    }
                    result = context.SaveChanges() > 0 ? SaveResult.SUCCESS : SaveResult.FAILURE;
                }
            }
            catch (Exception ex)
            {
                _logService.Error(ex.Message, ex);
                result = SaveResult.FAILURE;
            }
            return result;
        }
        /// <summary>
        /// Updates the specified entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public SaveResult Update(MSTServiceDto entity)
        {
            SaveResult result = SaveResult.FAILURE;

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

                    service.Name = entity.Name;
                    service.IsDeleted = entity.IsDeleted;
                    service.Description = entity.Description;
                    service.LastUpdatedBy = entity.LastUpdatedBy;
                    service.LastUpdate = DateTime.Now;

                    context.Entry<MST_Services>(service).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 specified entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public SaveResult Update(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.MasterId = entity.MasterId;
                    assembly.IsDeleted = entity.IsDeleted;
                    assembly.AnalystFrom = entity.AnalystFrom;
                    assembly.AnalystTo = entity.AnalystTo;
                    assembly.LastUpdatedBy = entity.LastUpdatedBy;
                    assembly.UpdatedDate = DateTime.Now;

                    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;
        }
        /// <summary>
        /// Deletes the by.
        /// </summary>
        /// <param name="Id">The identifier.</param>
        /// <returns></returns>
        public SaveResult DeleteBy(int Id)
        {
            SaveResult result = SaveResult.FAILURE;

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

                    context.Entry<MST_Services>(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;
        }
        /// <summary>
        /// Updates the specified entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public SaveResult Update(MSTProductDto entity)
        {
            SaveResult result = SaveResult.FAILURE;

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

                    product.Name = entity.Name;
                    product.MainPerson = entity.MainPerson;
                    product.SecondaryPerson = entity.SecondaryPerson;
                    product.TertiaryPerson = entity.TertiaryPerson;
                    product.LabSiteId = entity.LabSiteId;
                    product.IsDeleted = entity.IsDeleted;
                    product.Description = entity.Description;
                    product.LastUpdatedBy = entity.LastUpdatedBy;
                    product.LastUpdate = DateTime.Now;

                    context.Entry<MST_Product>(product).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;
        }