Exemplo n.º 1
0
        private JsonNetResult CreateUser(User user)
        {
            try
            {
                string prop = null;
                ModelState.Remove("Password");
                if (!ModelState.IsValid)
                {
                    return(JsonNet.JsonError(Resources.Global.General_ReceivedInvalidData));
                }
                if (!IsUnique(user, ref prop))
                {
                    return(JsonNet.JsonError(String.Format(Resources.Global.General_PropertyIsNotUnique, prop)));
                }

                user.Salt = Guid.NewGuid().ToString();
                string hash = Utilities.General.HashString(user.NewPassword + user.Salt);
                user.Password = hash;

                repo.Add(user);
                repo.Save();
                return(JsonNet.JsonOKRecord(user));
            }
            catch (Exception ex)
            {
                return(JsonNet.JsonError(ex.Message + '\n' + ex.StackTrace));
            }
        }
Exemplo n.º 2
0
        public JsonNetResult UploadFile(HttpPostedFileBase fileData, string entity)
        {
            try
            {
                if (fileData.ContentLength > 0)
                {
                    var file = JsonConvert.DeserializeObject <FileModel>(entity);
                    file.Name = System.IO.Path.GetFileName(fileData.FileName);

                    if (!db.Files.Any(f => f.Name.Equals(file.Name)))
                    {
                        var buffer = new byte[fileData.ContentLength];
                        fileData.InputStream.Read(buffer, 0, fileData.ContentLength);
                        Utilities.FileUtility.WriteToFile(file.Name, buffer);

                        db.Files.Add(file);
                        db.SaveChanges();

                        return(JsonNet.JsonOKRecord(file));
                    }
                    else
                    {
                        return(JsonNet.JsonError(String.Format(Resources.Global.Error_FileAlreadyExists, file.Name)));
                    }
                }
                else
                {
                    return(JsonNet.JsonError(Resources.Global.Error_UploadFailed));
                }
            }
            catch (Exception ex)
            {
                return(JsonNet.JsonError(ex.Message + '\n' + ex.StackTrace));
            }
        }
Exemplo n.º 3
0
 public override JsonNetResult Delete(List <int> IDs)
 {
     if (db.Users.Any(u => IDs.Contains(u.RoleID)))
     {
         return(JsonNet.JsonError(Resources.Global.Error_UserWithDeletedRole));
     }
     return(base.Delete(IDs));
 }
Exemplo n.º 4
0
        public JsonNetResult Restore(Backup backup)
        {
            if (BackupRoutine.Restore(backup))
            {
                return(JsonNet.JsonOK());
            }

            return(JsonNet.JsonError(Resources.Global.Backup_RestoreFailed));
        }
Exemplo n.º 5
0
        public JsonNetResult BackupNow()
        {
            if (BackupRoutine.SingleBackup())
            {
                return(JsonNet.JsonOK());
            }

            return(JsonNet.JsonError(Resources.Global.Backup_Failed));
        }
Exemplo n.º 6
0
        public JsonNetResult GetAppHealth()
        {
            if (db.AppLogs.Any(l => l.Seen == false && l.Type == AppLogType.Error || l.Type == AppLogType.Warning))
            {
                return(JsonNet.JsonError(string.Empty));
            }

            return(JsonNet.JsonOK());
        }
Exemplo n.º 7
0
 public JsonNetResult TestNetworkSettings(BackupSettings settings)
 {
     if (DirectoryUtility.IsPathAvailable(settings.NetworkShare, settings.NetworkUsername, settings.NetworkPassword))
     {
         return(JsonNet.JsonOK());
     }
     else
     {
         return(JsonNet.JsonError(Resources.Global.Backup_TestFailed));
     }
 }
Exemplo n.º 8
0
 public JsonNetResult GetModuleOptions()
 {
     try
     {
         return(JsonNet.JsonOKOptions(JtableUtil.GetOptions <Module>()));
     }
     catch (Exception ex)
     {
         return(JsonNet.JsonError(ex.Message + '\n' + ex.StackTrace));
     }
 }
Exemplo n.º 9
0
 public override JsonNetResult Edit(User user)
 {
     try
     {
         return(EditUser(user));
     }
     catch (Exception ex)
     {
         return(JsonNet.JsonError(ex.Message + '\n' + ex.StackTrace));
     }
 }
Exemplo n.º 10
0
 public override JsonNetResult Delete(List <int> IDs)
 {
     try
     {
         foreach (var ID in IDs)
         {
             var file = repo.GetByID(ID);
             Utilities.FileUtility.Delete(file.Name);
         }
         return(base.Delete(IDs));
     }
     catch (Exception ex)
     {
         return(JsonNet.JsonError(ex.Message + '\n' + ex.StackTrace));
     }
 }
Exemplo n.º 11
0
        private JsonNetResult EditUser(User user)
        {
            try
            {
                string prop = null;

                ModelState.Remove("Password");

                if (!ModelState.IsValid)
                {
                    return(JsonNet.JsonError(Resources.Global.General_ReceivedInvalidData));
                }
                if (!IsUnique(user, ref prop, true))
                {
                    return(JsonNet.JsonError(String.Format(Resources.Global.General_PropertyIsNotUnique, prop)));
                }

                var oldUser = base.db.Users.AsNoTracking().Where(u => u.ID == user.ID).First();
                user.Password = oldUser.Password;
                user.Salt     = oldUser.Salt;

                if (!String.IsNullOrEmpty(user.EditPassword))
                {
                    string hash = Utilities.General.HashString(user.EditPassword + user.Salt);
                    user.Password = hash;
                }
                else
                {
                    user.EditPassword = null;
                }

                // Prevent validation errors
                user.NewPassword = "******";

                repo.Edit(user);
                repo.Save();

                return(JsonNet.JsonOKRecord(user));
            }
            catch (Exception ex)
            {
                return(JsonNet.JsonError(ex.Message + '\n' + ex.StackTrace));
            }
        }
Exemplo n.º 12
0
        public JsonNetResult GetDriveInfo(string path)
        {
            bool  success;
            ulong freeBytes, totalBytes, totalFreeBytes;

            success = GetDiskFreeSpaceEx(path, out freeBytes,
                                         out totalBytes, out totalFreeBytes);

            if (success)
            {
                return(JsonNet.JsonOKRecord(new Drive()
                {
                    FreeSpace = General.BytesToGigaBytes(freeBytes),
                    TotalSpace = General.BytesToGigaBytes(totalBytes),
                    Name = path,
                    VolumeLabel = path
                }));
            }
            else
            {
                return(JsonNet.JsonError("Could not get drive info"));
            }
        }
Exemplo n.º 13
0
        public JsonNetResult GetRoleOptions()
        {
            try
            {
                var roles = repo.OrderBy(r => r.Name)
                            .Select(r => new JTableOption
                {
                    DisplayText = r.Name,
                    Value       = r.ID
                });

                if (roles.Count() > 0)
                {
                    return(JsonNet.JsonOKOptions(roles));
                }

                return(JsonNet.JsonNoOptions(StringFormatters.NotAvailable(Resources.Global.General_Roles.ToLower())));
            }
            catch (Exception ex)
            {
                return(JsonNet.JsonError(ex.Message + '\n' + ex.StackTrace));
            }
        }
Exemplo n.º 14
0
        public JsonNetResult GetBackupStatus()
        {
            var log = db.AppLogs.AsNoTracking().Where(l => l.Module == Module.Backup).OrderByDescending(l => l.ID).FirstOrDefault();

            return((log != null && log.Type != AppLogType.Success) ? JsonNet.JsonError(string.Empty) : JsonNet.JsonOK());
        }