Пример #1
0
        public static MachineConfig AddMachine(string machineName, bool isKpmgOnly, bool isPreservation, string RackNo)
        {
            using (var db = new SSCDbContext())
            {
                var mc = new MachineConfig
                {
                    MachineName = machineName,
                    KPMGOnly = (isKpmgOnly == true) ? "Y" : "N",
                    Preservation = (isPreservation == true) ? "Y" : "N",
                    RackNo = RackNo,
                    CreatedTS = System.DateTime.Now,
                    CreatedBy = System.Environment.UserDomainName + @"\" + System.Environment.UserName,
                    ModifiedTS = null,
                    ModifiedBy = null,
                    DeletedTS = null,
                    DeletedBy = null,
                    IsDeleted = false
                };

                db.MachineConfigs.Add(mc);
                db.SaveChanges();

                MachineConfigLog(machineName, null, null, null, isKpmgOnly, isPreservation, RackNo, MachineActionType.Insert);

                return mc;
            }
        }
Пример #2
0
        //uspDeleteMachineProfiles
        public static ResultModel DeleteMachine(string machineName)
        {
            int surveyRowId;
            if (IsMachineInProgress(machineName, out surveyRowId))
            {
                return new ResultModel
                {
                    IsSuccess = false,
                    Msg = "Unable to delete machine detail. Machine is currently being used by NSTID: " + surveyRowId + ". Machine processing must be completed before any change can be made."
                };
            }
            else
            {
                using (var db = new SSCDbContext())
                {
                    var original = db.MachineConfigs.Find(machineName);

                    original.IsDeleted = true;
                    original.DeletedTS = DateTime.Now;
                    original.DeletedBy = System.Environment.UserDomainName + @"\" + System.Environment.UserName;

                    db.SaveChanges();

                    MachineConfigLog(machineName, original.KPMGOnly.StringToBool(), original.Preservation.StringToBool(), original.RackNo, null, null, null, MachineActionType.Deactivate);
                }

                return new ResultModel
                {
                    IsSuccess = true,
                };
            }
        }
Пример #3
0
        public static List<SSC.Model.EFModel.RollingComment> AddComment(int surveyRowId, string comment)
        {
            using (var db = new SSCDbContext())
            {
                db.RollingComments.Add(new Model.EFModel.RollingComment
                {
                    Comments = comment,
                    MachineName = string.Format("[{0}]-{1}", System.Environment.UserName, System.Environment.MachineName),
                    SequenceNumber = db.RollingComments.Count(x => x.SurveyRowID == surveyRowId) + 1,
                    SurveyRowID = surveyRowId,
                    TimeStamp = DateTime.UtcNow
                });

                db.SaveChanges();

                return GetComment(surveyRowId);
            }
        }
Пример #4
0
        public static ResultModelWithSurveyWorkbook DeleteSurveyWorkbook(int surveyRowId, int workbookNum)
        {
            using (var db = new SSCDbContext())
            {
                var original = db.Surveys.Find(surveyRowId);

                if (AppConfig.ToUseSP)
                {

                    SqlParameter p1 = new SqlParameter("@SurveyRowId", surveyRowId);
                    SqlParameter p2 = new SqlParameter("@WorkbookNum", workbookNum);

                    try
                    {
                        db.Database.ExecuteSqlCommand("EXEC uspDeleteWorkbook @SurveyRowID, @WorkbookNum", p1, p2);

                        return new ResultModelWithSurveyWorkbook
                        {
                            IsSuccess = true,
                            SurveyWorkbooks = original.SurveyWorkbooks.ToList(),
                            CRUDTimestamp = DateTime.UtcNow,
                        };

                    }
                    catch (SqlException ex)
                    {
                        return new ResultModelWithSurveyWorkbook { IsSuccess = false, Msg = ex.Message };
                    }
                }
                else
                {
                    original.SurveyWorkbooks.Remove(db.SurveyWorkbooks.Find(surveyRowId, workbookNum));

                    db.SaveChanges();
                }

                return new ResultModelWithSurveyWorkbook { IsSuccess = true, SurveyWorkbooks = original.SurveyWorkbooks.ToList() };
            }
        }
Пример #5
0
        public static ResultModelWithSurveyWorkbook AddSurveyWorkbook(int surveyRowId, int workbookNum, string workbookName, DateTime requiredDate)
        {
            using (var db = new SSCDbContext())
            {
                var original = db.Surveys.Find(surveyRowId);

                if (AppConfig.ToUseSP)
                {
                    SqlParameter p1 = new SqlParameter("@SurveyRowId", surveyRowId);
                    SqlParameter p2 = new SqlParameter("@WorkbookNum", workbookNum);
                    SqlParameter p3 = new SqlParameter("@WorkbookName", workbookName);
                    SqlParameter p4 = new SqlParameter("@RequiredDate", requiredDate);
                    SqlParameter p5 = new SqlParameter("@UserId", System.Environment.UserName);

                    try
                    {
                        db.Database.ExecuteSqlCommand("EXEC uspAddNewWBInExistingSurvey @SurveyRowID, @WorkbookNum, @WorkbookName, @RequiredDate, @UserId", p1, p2, p3, p4, p5);

                        return new ResultModelWithSurveyWorkbook
                        {
                            IsSuccess = true,
                            SurveyWorkbooks = original.SurveyWorkbooks.ToList(),
                            CRUDTimestamp = DateTime.UtcNow,
                        };

                    }
                    catch (SqlException ex)
                    {
                        return new ResultModelWithSurveyWorkbook { IsSuccess = false, Msg = ex.Message };
                    }
                }
                else
                {
                    var result = db.FileActivities
                            .Where(x => x.SurveyRowID == surveyRowId)
                            .Include(x => x.Activity)
                        //.Where(x => x.SurveyRowID == surveyRowId)
                            .ToList();

                    if(result.GroupBy(x => new { x.SurveyRowID, x.ActivityId }).Select(y => y.OrderByDescending(z => z.FAId)).Select(a => a.First()).Any(b => b.Activity.ActivityName.StartsWith("PDFREVIEW", StringComparison.OrdinalIgnoreCase)))
                    {
                        return new ResultModelWithSurveyWorkbook { IsSuccess = false, Msg = "Workbook can not be added as one of the workbook is already available for the User Acknowledgement", SurveyWorkbooks = original.SurveyWorkbooks.ToList() };
                    }
                    else
                    {
                        original.SurveyWorkbooks.Add(new SSC.Model.EFModel.SurveyWorkbook
                        {
                            SurveyRowId = surveyRowId,
                            WorkbookNum = workbookNum,
                            WorkbookName = workbookName,
                            RequiredDate = requiredDate,
                            InsertDate = DateTime.UtcNow,
                            InsertBy = System.Environment.UserName,
                            LastUpdateDate = DateTime.UtcNow,
                            LastUpdateBy = System.Environment.UserName
                        });
                        db.SaveChanges();
                    }
                }

                return new ResultModelWithSurveyWorkbook { IsSuccess = true, SurveyWorkbooks = original.SurveyWorkbooks.ToList() };
            }
        }
Пример #6
0
        private static void MachineConfigLog(string machineName, bool? isKpmgOnlyOld, bool? isPreservationOld, string RackNoOld, 
            bool? isKpmgOnlyNew, bool? isPreservationNew, string RackNoNew
            , MachineActionType machineActionType)
        {
            using (var db = new SSCDbContext())
            {
                var mc = new MachineConfigLog
                {
                    MachineName = machineName,

                    PreservationOld = isPreservationOld.BoolToString("YN"),
                    KPMGOnlyOld = isKpmgOnlyOld.BoolToString("YN"),

                    RackNoOld = RackNoOld,

                    Action = machineActionType.ToString(),
                    ActionBy = System.Environment.UserDomainName + @"\" + System.Environment.UserName,
                    ActionTS = System.DateTime.Now,

                    PreservationNew = isPreservationNew.BoolToString("YN"),
                    KPMGOnlyNew = isKpmgOnlyNew.BoolToString("YN"),

                    RackNoNew = RackNoNew
                };

                db.MachineConfigLogs.Add(mc);
                db.SaveChanges();
            }
        }
Пример #7
0
        //uspUpdateMachineProfiles
        public static ResultModel UpdateMachine(string machineName, bool isKpmgOnly, bool isPreservation, string RackNo)
        {
            int surveyRowId;
            if (IsMachineInProgress(machineName, out surveyRowId))
            {
                return new ResultModel
                {
                    IsSuccess = false,
                    Msg = "Unable to update machine detail. Machine is currently being used by NSTID: " + surveyRowId + ". Machine processing must be completed before any change can be made."
                };
            }
            else
            {
                using (var db = new SSCDbContext())
                {
                    var original = db.MachineConfigs.Find(machineName);

                    var oldKPMGOnly = original.KPMGOnly;
                    var oldPreservation = original.Preservation;
                    var oldRackNo = original.RackNo;

                    original.KPMGOnly = isKpmgOnly ? "Y" : "N";
                    original.Preservation = isPreservation ? "Y" : "N";
                    original.RackNo = string.IsNullOrWhiteSpace(RackNo) ? string.Empty : RackNo;
                    original.ModifiedTS = DateTime.Now;
                    original.ModifiedBy = System.Environment.UserDomainName + @"\" + System.Environment.UserName;

                    db.SaveChanges();

                    MachineConfigLog(machineName, oldKPMGOnly.StringToBool(), oldPreservation.StringToBool(), oldRackNo, isKpmgOnly, isPreservation, RackNo, MachineActionType.Update);
                }

                return new ResultModel
                {
                    IsSuccess = true,
                };
            }
        }
Пример #8
0
        //uspUndeleteMachineProfiles
        public static ResultModel UndeleteMachine(string machineName)
        {
            using (var db = new SSCDbContext())
            {
                var original = db.MachineConfigs.Find(machineName);

                original.IsDeleted = false;
                original.DeletedTS = null;
                original.DeletedBy = string.Empty;
                original.ModifiedTS = DateTime.Now;
                original.ModifiedBy = System.Environment.UserDomainName + @"\" + System.Environment.UserName;

                db.SaveChanges();

                MachineConfigLog(machineName, original.KPMGOnly.StringToBool(), original.Preservation.StringToBool(), original.RackNo, null, null, null, MachineActionType.Activate);
            }

            return new ResultModel
            {
                IsSuccess = true,
            };
        }
Пример #9
0
        //uspThrashMachineProfiles
        public static ResultModel ThrashMachine(string machineName)
        {
            using (var db = new SSCDbContext())
            {
                var original = db.MachineConfigs.Find(machineName);
                db.MachineConfigs.Remove(original);
                db.SaveChanges();

                MachineConfigLog(machineName, original.KPMGOnly.StringToBool(), original.Preservation.StringToBool(), original.RackNo, null, null, null, MachineActionType.Delete);

                return new ResultModel
                {
                    IsSuccess = true,
                };
            }
        }