/// <summary>
        /// Function is Used to Create Folder
        /// </summary>
        /// <param name="folderName"></param>
        /// <returns></returns>
        public ActionResult CreateFolder(string folderName, string folderPath)
        {
            folderName = @"\" + folderName;

            using (var db = new SoftwareBackUpEntities())
            {
                //var user = db.Users.FirstOrDefault(x => x.Email == User.Identity.Name);
                //var folder = db.Folders.FirstOrDefault(x => x.UserId == user.Id);

                //var path = string.Concat(folder.Path,folderName);
                var path = string.Concat(folderPath, folderName);
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                    Console.WriteLine("Folder Created");
                }
                else
                {
                    TempData["error"] = "Folder Already Exist";
                    return(RedirectToAction("Index", new { path = folderPath }));
                }
            }



            return(RedirectToAction("Index", new { path = folderPath }));
        }
Beispiel #2
0
        public ActionResult SignUp(RegisterViewModel model)
        {
            User user = new User();

            user.FirstName = model.FirstName;
            user.LastName  = model.LastName;
            user.Email     = model.Email;
            user.Password  = model.Password;
            user.Contact   = model.Contact;
            user.Country   = model.Country;
            UserRole role = new UserRole();

            role.UserId = user.Id;
            role.Role   = "user";
            using (var db = new SoftwareBackUpEntities())
            {
                bool IsTrue = db.Users.Any(x => x.Email == model.Email);
                if (!IsTrue)
                {
                    db.Users.Add(user);
                    db.UserRoles.Add(role);
                    db.SaveChanges();
                }
                else
                {
                    ModelState.AddModelError("", "Email Already Exist");

                    return(View());
                }
            }

            return(RedirectToAction("Login"));
        }
Beispiel #3
0
 /// <summary>
 /// Admin can unblock user on the basis of id
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public ActionResult UnBlock(int id)
 {
     using (var db = new SoftwareBackUpEntities())
     {
         var user = db.Users.FirstOrDefault(x => x.Id == id);
         user.Status = false;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
 }
        public ActionResult Index(HttpPostedFileBase file, string folderPath)
        {
            using (var db = new SoftwareBackUpEntities())
            {
                string fileName = Path.GetFileName(file.FileName);

                //Combine path
                string fullPath = Path.Combine(folderPath, fileName);


                file.SaveAs(fullPath);

                return(RedirectToAction("Index", new { Path = folderPath }));
            }
        }
        /// <summary>
        /// This function is used to get files and Folders of Current User
        ///
        /// </summary>
        /// <param name="path">Pass path of folder That you Want to open</param>
        /// <returns></returns>
        public ActionResult Index(string path)
        {
            Folder folder;

            string[] dirs;
            string[] files;
            string   p = "";

            using (var db = new SoftwareBackUpEntities())
            {
                //Find Account of Current Login User
                var user = db.Users.FirstOrDefault(x => x.Email == User.Identity.Name);
                //Find Directory of Currently login User
                folder = db.Folders.FirstOrDefault(x => x.UserId == user.Id);
                //Find all folders in a main directory of a

                if (!String.IsNullOrEmpty(path))
                {
                    p = path;
                    //dirs = Directory.GetDirectories(path, "*", SearchOption.AllDirectories);
                    dirs = Directory.GetDirectories(path);
                    //files = Directory.GetFiles(path, "*", SearchOption.AllDirectories);
                    files = Directory.GetFiles(path);
                }
                else
                {
                    p = folder.Path;
                    //dirs = Directory.GetDirectories(folder.Path, "*", SearchOption.AllDirectories);
                    dirs = Directory.GetDirectories(folder.Path);
                    //files = Directory.GetFiles(folder.Path, "*", SearchOption.AllDirectories);
                    files = Directory.GetFiles(folder.Path);
                }
                var viewModel = new FolderViewModel()
                {
                    Path    = p,
                    User    = user,
                    Files   = files,
                    Folders = dirs
                };
                if (TempData["error"] == null)
                {
                    TempData["error"] = "";
                }
                ViewBag.ErrorMessage = TempData["error"].ToString();
                //var dirs = Directory.GetDirectories(folder.Path).ToList();
                return(View(viewModel));
            }
        }
Beispiel #6
0
        public ActionResult Login(MemberShip model)
        {
            using (var db = new SoftwareBackUpEntities())
            {
                bool isValid = db.Users.Any(x => x.Email == model.Email && x.Password == model.Password && x.Status == false);

                if (isValid)
                {
                    FormsAuthentication.SetAuthCookie(model.Email, false);
                    var user = db.Users.FirstOrDefault(x => x.Email == model.Email);
                    var role = db.UserRoles.FirstOrDefault(x => x.UserId == user.Id);
                    if (role.Role == "admin")
                    {
                        return(RedirectToAction("Index", "Admin"));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "User"));
                    }
                }
                ModelState.AddModelError("", "Invalid username and password");
                return(View());
            }
        }