Exemplo n.º 1
0
        public static ErrorLog_DTO Add(Exception exception, string additionalInfo = null)
        {
            try
            {
                using (HomesteadViewerContext context = new HomesteadViewerContext())
                {
                    ErrorLog_DTO ErrorLog = new ErrorLog_DTO()
                    {
                       UserId = exception.UserId(),
                        Message = exception.Message,
                        TimeStamp = exception.TimeStamp(),
                        Classname = exception.ClassName(),
                        LineNumber = exception.LineNumber(),
                        MethodName = exception.MethodName(),
                        InnerException = (exception.InnerException != null) ? exception.InnerException.Message : "",
                        AdditionalIfno = additionalInfo
                    };

                    context.ErrorLogs.Add(ErrorLog);
                    context.SaveChanges();
                    return context.ErrorLogs.FirstOrDefault(e=>e.UserId == ErrorLog.UserId && e.TimeStamp == ErrorLog.TimeStamp);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 2
0
        public static UserTimeLog_DTO Add(int userId)
        {
            if (!User_DTO.Exists(userId))
                return null;
            try
            {
                using (HomesteadViewerContext context = new HomesteadViewerContext())
                {
                    var userLog = new UserTimeLog_DTO()
                    {
                         FirstLogDate = DateTime.Now,
                         LastLogDate = DateTime.Now,
                         Duration = 0,
                          UserId = userId
                    };

                    context.UserLogs.Add(userLog);
                    context.SaveChanges();

                    return GetLast(userId);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 3
0
        public static Setting_DTO UpdateSetting(string settingGroup, string settingKey, string settingValue)
        {
            try
            {
                using (HomesteadViewerContext context = new HomesteadViewerContext())
                {
                    var setting = GetSetting(settingKey);
                    if (setting == null)
                        throw new Exception("Setting Does Not Exist.");

                    setting.SettingGroup = (string.IsNullOrEmpty(settingGroup)) ? "" : settingGroup;
                    setting.SettingValue = setting.SettingValue;

                    context.Settings.Attach(setting);
                    context.Entry(setting).State = System.Data.Entity.EntityState.Modified;
                    context.SaveChanges();
                    return GetSetting(settingKey);
                }
            }
            catch (Exception ex)
            {
                ex.Log();
                return null;
            }
        }
Exemplo n.º 4
0
        public static bool AddUpdateExemption(Exemption exemption)
        {
            try
            {
                using (HomesteadViewerContext context = new HomesteadViewerContext())
                {
                    var e = context.Exemptions.Find(exemption.ID);
                    //Add Exemption
                    if(e == null)
                        return AddExemption(exemption);

                        e.AssignedUsers.Clear();
                        context.SaveChanges();
                }
                using (HomesteadViewerContext context = new HomesteadViewerContext())
                {
                    var e = context.Exemptions.Find(exemption.ID);
                    e.AssignedUsers = exemption.AssignedUsers;
                    context.SaveChanges();
                    return true;
                }
            }
            catch (Exception ex)
            {
                return false;
            }
        }
Exemplo n.º 5
0
 public static int Count()
 {
     using (var context = new HomesteadViewerContext())
     {
         return context.UserLogs.Count();
     }
 }
Exemplo n.º 6
0
 public static GridColumn_DTO Get(string propertyName)
 {
     try
     {
         using (HomesteadViewerContext context = new HomesteadViewerContext())
         {
             return context.GridColumns.FirstOrDefault(x => x.PropertyName.ToLower() == propertyName.ToLower()) ?? null;
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 7
0
 public static GridColumn_DTO Get(Func<GridColumn_DTO, bool> func)
 {
     try
     {
         using (HomesteadViewerContext context = new HomesteadViewerContext())
         {
             return context.GridColumns.FirstOrDefault(func) ?? null;
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 8
0
 public static Setting_DTO GetSetting(string settingKey)
 {
     try
     {
         using (HomesteadViewerContext context = new HomesteadViewerContext())
         {
             return context.Settings.FirstOrDefault(x => x.SettingKey == settingKey) ?? new Setting_DTO();
         }
     }
     catch (Exception ex)
     {
         ex.Log();
         return null;
     }
 }
Exemplo n.º 9
0
 public static List<Setting_DTO> GetAllSettings()
 {
     try
     {
         using (HomesteadViewerContext context = new HomesteadViewerContext())
         {
             return context.Settings.ToList();
         }
     }
     catch (Exception ex)
     {
         ex.Log();
         return null;
     }
 }
Exemplo n.º 10
0
 public static bool AddExemption(Exemption exemption)
 {
     try
     {
         using (HomesteadViewerContext context = new HomesteadViewerContext())
         {
                 foreach (var user in exemption.AssignedUsers)
                     context.Users.Attach(user);
                 context.Exemptions.Add(exemption);
                 context.SaveChanges();
                 return true;
             }
     }
     catch (Exception ex)
     {
         return false;
     }
 }
Exemplo n.º 11
0
        /// <summary>
        /// Adds a new user
        /// </summary>
        /// <param name="name"></param>
        /// <param name="phone"></param>
        /// <param name="email"></param>
        /// <returns>bool</returns>
        public static bool AddUser(string userName, string phone, string email)
        {
            try
            {
                using (HomesteadViewerContext context = new HomesteadViewerContext())
                {
                    User user = new User()
                    {
                        UserName = userName,
                        Phone = phone,
                        EmailAddress = email
                    };

                    context.Users.Add(user);
                    context.SaveChanges();
                    return true;
                }
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        public static AdministrativeProperties_DTO AddOrUpdate(AdministrativeProperties_DTO administrativeProperties)
        {
            try
            {
                if (administrativeProperties.AssignedUserID != null)
                    administrativeProperties.AssignedUserID = (administrativeProperties.AssignedUserID <= 0) ? null : administrativeProperties.AssignedUserID;

                var ap = AdministrativeProperties_DTO.Get(administrativeProperties.OnlineExemptionID);
                //Creaet New
                if (ap == null)
                {
                    using (var context = new HomesteadViewerContext())
                    {
                        var newAp = new AdministrativeProperties_DTO()
                        {
                            OnlineExemptionID = administrativeProperties.OnlineExemptionID,
                            Comment = administrativeProperties.Comment,
                            FollowUpDate = administrativeProperties.FollowUpDate,
                            Status = administrativeProperties.Status,
                            QuickrefID = administrativeProperties.QuickrefID,
                            AssignedUserID = administrativeProperties.AssignedUserID
                        };

                        if (newAp.Status != ExemptionStatus.NotWorked)
                            newAp.DateStatusChanged = DateTime.Now;

                        if (administrativeProperties.AssignedUserID != null)
                            newAp.DateAssigned = DateTime.Now;

                        context.AdministrativeProperties_Collection.Add(newAp);
                        context.SaveChanges();

                        return LogChange(administrativeProperties.OnlineExemptionID);
                    }
                }

                //Update
                using (var context = new HomesteadViewerContext())
                {
                    ap.Comment = administrativeProperties.Comment;
                    ap.FollowUpDate = administrativeProperties.FollowUpDate;
                    ap.QuickrefID = administrativeProperties.QuickrefID;

                    if (ap.Status != administrativeProperties.Status)
                        ap.DateStatusChanged = DateTime.Now;
                    ap.Status = administrativeProperties.Status;

                    if (ap.AssignedUserID != administrativeProperties.AssignedUserID)
                        ap.DateAssigned = DateTime.Now;

                    ap.AssignedUserID = administrativeProperties.AssignedUserID;

                    context.AdministrativeProperties_Collection.Attach(ap);
                    context.Entry(ap).State = System.Data.Entity.EntityState.Modified;
                    context.SaveChanges();
                    return LogChange(administrativeProperties.OnlineExemptionID);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static AdministrativeProperties_DTO LogChange(int onlineExemptionID)
        {
            try
            {
                using (var context = new HomesteadViewerContext())
                {
                    var ap = AdministrativeProperties_DTO.Get(onlineExemptionID);
                    if (ap == null)
                        return null;

                    ap.Modified = DateTime.Now;
                    ap.ModifiedBy = UserSession.GetCurrentUser().FullName;

                    context.AdministrativeProperties_Collection.Attach(ap);
                    context.Entry(ap).State = System.Data.Entity.EntityState.Modified;
                    context.SaveChanges();
                    return AdministrativeProperties_DTO.Get(onlineExemptionID);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static List<AdministrativeProperties_DTO> GetOrphanedData()
        {
            try
            {
                using (var context = new HomesteadViewerContext())
                {
                    var ap_c = context.AdministrativeProperties_Collection.ToList();

                    //Check if object exists in Master Exemptions

                    var orphans = ap_c.Where(ap => !MasterExemption_DTO.Exists(ap.OnlineExemptionID)).ToList();
                    //Check if Quick Ref ID's Work

                    //orphans.AddRange(ap_c.Where(ap => MasterExemption_DTO.Exists(x => x.OnlineExemptionID == ap.OnlineExemptionID && x.QuickrefID != ap.QuickrefID)).ToList());
                    return orphans;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 public static List<AdministrativeProperties_DTO> GetAll(Func<AdministrativeProperties_DTO, bool> func = null)
 {
     try
     {
         using (var context = new HomesteadViewerContext())
         {
             if (func != null)
                 return context.AdministrativeProperties_Collection.Where(func).ToList();
             return context.AdministrativeProperties_Collection.ToList();
         }
     }
     catch (Exception ex)
     {
         return null;
     }
 }
 public static AdministrativeProperties_DTO Get(Func<AdministrativeProperties_DTO, bool> func)
 {
     try
     {
         using (var context = new HomesteadViewerContext())
         {
             return context.AdministrativeProperties_Collection
                 .FirstOrDefault(func);
         }
     }
     catch (Exception ex)
     {
         return null;
     }
 }
 public static AdministrativeProperties_DTO Get(int onlineExemptionId)
 {
     try
     {
         using (var context = new HomesteadViewerContext())
         {
             return context.AdministrativeProperties_Collection
                 .FirstOrDefault(x => x.OnlineExemptionID == onlineExemptionId);
         }
     }
     catch (Exception ex)
     {
         return null;
     }
 }
Exemplo n.º 18
0
 public static List<UserTimeLog_DTO> GetAll(Func<UserTimeLog_DTO, bool> func)
 {
     try
     {
         using (HomesteadViewerContext context = new HomesteadViewerContext())
         {
             return context.UserLogs.Where(func).ToList();
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 19
0
 public static List<User_DTO> GetAll()
 {
     try
     {
         using (HomesteadViewerContext context = new HomesteadViewerContext())
         {
             return context.Users.ToList();
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 20
0
        public static bool UpdateUser(int id, string firstName, string lastName, string phone, string email)
        {
            try
            {
                using (HomesteadViewerContext context = new HomesteadViewerContext())
                {
                    var user = Get(id);
                    if (user == null)
                        throw new Exception("User Could Not Be Found");

                    user.FirstName = firstName;
                    user.LastName = lastName;
                    user.Phone = phone;
                    user.EmailAddress = email;

                    context.Users.Attach(user);
                    context.Entry(user).State = System.Data.Entity.EntityState.Modified;
                    context.SaveChanges();
                    return true;
                }
            }
            catch (Exception ex)
            {
                return false;
            }
        }
Exemplo n.º 21
0
        public static User_DTO UpdateUser(User_DTO user)
        {
            Mapper.CreateMap<Models.User_DTO, Models.User_DTO>()
                .ForMember(dest => dest.Id, opt => opt.Ignore());

            using (HomesteadViewerContext context = new HomesteadViewerContext())
            {
                try
                {
                    var c = Get(user.Id);
                    if (c == null)
                        throw new Exception("User Could Not Be Found");
                    Mapper.Map<Models.User_DTO, Models.User_DTO>(user, c);

                    context.Users.Attach(c);
                    context.Entry(c).State = System.Data.Entity.EntityState.Modified;
                    context.SaveChanges();
                    return Get(user.Id);
                }
                catch (Exception ex)
                {
                    return null;
                }
            }
        }
Exemplo n.º 22
0
        public static UserTimeLog_DTO Update(UserTimeLog_DTO userLog)
        {
            Mapper.CreateMap<Models.UserTimeLog_DTO, Models.UserTimeLog_DTO>()
                .ForMember(dest => dest.Id, opt => opt.Ignore());

            using (HomesteadViewerContext context = new HomesteadViewerContext())
            {
                try
                {
                    var c = Get(userLog.Id);
                    if (c == null)
                        throw new Exception("User Could Not Be Found");
                    Mapper.Map<Models.UserTimeLog_DTO, Models.UserTimeLog_DTO>(userLog, c);

                    TimeSpan span = c.LastLogDate - c.FirstLogDate;
                    c.Duration = (int)span.TotalMilliseconds;

                    context.UserLogs.Attach(c);
                    context.Entry(c).State = System.Data.Entity.EntityState.Modified;
                    context.SaveChanges();
                    return Get(userLog.Id);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
Exemplo n.º 23
0
        public static void RemoveAll()
        {
            try
            {
                using (HomesteadViewerContext context = new HomesteadViewerContext())
                {

                    context.Database.ExecuteSqlCommand("TRUNCATE TABLE [UserLogs]");
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 24
0
 public static UserTimeLog_DTO GetLast(Func<UserTimeLog_DTO, bool> func)
 {
     try
     {
         using (HomesteadViewerContext context = new HomesteadViewerContext())
         {
             return context.UserLogs.OrderByDescending(ul => ul.Id).FirstOrDefault(func);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 25
0
        public static Setting_DTO UpdateSetting(Setting_DTO setting)
        {
            Mapper.CreateMap<Models.Setting_DTO, Models.Setting_DTO>();

            using (HomesteadViewerContext context = new HomesteadViewerContext())
            {
                try
                {
                    var s = GetSetting(setting.SettingKey);
                    if (s == null)
                        throw new Exception("Setting Does Not Exist");

                    Mapper.Map(setting, s);
                    s.SettingGroup = (string.IsNullOrEmpty(setting.SettingGroup)) ? "" : setting.SettingGroup;
                    context.Settings.Attach(s);
                    context.Entry(s).State = System.Data.Entity.EntityState.Modified;
                    context.SaveChanges();
                    return GetSetting(s.SettingKey);
                }
                catch (Exception ex)
                {
                    ex.Log();
                    return null;
                }
            }
        }
 public static int Count(Func<AdministrativeProperties_DTO, bool> func)
 {
     try
     {
         using (var context = new HomesteadViewerContext())
         {
             return context.AdministrativeProperties_Collection.Count(func);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 27
0
 public static int Count(Func<UserTimeLog_DTO, bool> func)
 {
     using (var context = new HomesteadViewerContext())
     {
         return context.UserLogs.Count(func);
     }
 }
Exemplo n.º 28
0
 public static UserTimeLog_DTO Get(Func<UserTimeLog_DTO, bool> func)
 {
     try
     {
         using (HomesteadViewerContext context = new HomesteadViewerContext())
         {
             return context.UserLogs.Find(func);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 29
0
 public static UserTimeLog_DTO Get(int id)
 {
     try
     {
         using (HomesteadViewerContext context = new HomesteadViewerContext())
         {
             return context.UserLogs.Find(id);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 30
0
 public static User_DTO Get(Func<User_DTO, bool> func)
 {
     try
     {
         using (HomesteadViewerContext context = new HomesteadViewerContext())
         {
             return context.Users.Where(func).FirstOrDefault();
         }
     }
     catch (Exception ex)
     {
         return null;
     }
 }