コード例 #1
0
        public FileDB SaveFile(FileDB file, string action)
        {
            FileManagerDAL fmDAL = new FileManagerDAL();
            FileDB         target;

            if (file.FileId != 0)
            {
                target = fmDAL.Files.Find(file.FileId);
            }
            else
            {
                target = file;
            }

            switch (action)
            {
            case "upload":
            {
                target.UploadTime   = DateTime.Now;
                target.ModifiedTime = DateTime.Now;
                target.Version      = 1;
                target.FormerId     = null;

                fmDAL.Entry(target).State = EntityState.Added;
                break;
            }

            case "mark delete":
            {
                target.isDelete     = true;
                target.ModifiedTime = DateTime.Now;

                fmDAL.Entry(target).State = EntityState.Modified;
                break;
            }

            case "delete":
            {
                target.FilePath     = null;
                target.ModifiedTime = DateTime.Now;

                fmDAL.Entry(target).State = EntityState.Modified;
                break;
            }

            case "modify":
            {
                file.UploadTime   = target.UploadTime;
                file.ModifiedTime = DateTime.Now;
                file.FormerId     = target;
                target.isDelete   = true;

                fmDAL.Entry(file).State   = EntityState.Added;
                fmDAL.Entry(target).State = EntityState.Modified;
                break;
            }
            }
            fmDAL.SaveChanges();
            return(file);
        }
コード例 #2
0
        public FileDB SaveFile(FileDB file)
        {
            int id = file.FileId;

            FileManagerDAL fmDAL  = new FileManagerDAL();
            FileDB         record = fmDAL.Files.Find(id);

            if (record == null || id == null)
            {
                fmDAL.Files.Add(file);
            }
            else
            {
                //fmDAL.Files.Attach(file);
                //DbContext.Entry(file).State = System.Data.EntityState.Modified;

                record.FileName     = file.FileName;
                record.FilePath     = file.FilePath;
                record.isDelete     = file.isDelete;
                record.ModifiedTime = file.ModifiedTime;
                record.UploadTime   = file.UploadTime;
                record.Version      = file.Version;
            }
            fmDAL.SaveChanges();
            return(file);
        }
コード例 #3
0
        public UserProfile ModifyUser(UserProfile user)
        {
            FileManagerDAL fmDAL = new FileManagerDAL();

            fmDAL.Entry(user).State = EntityState.Modified;
            fmDAL.SaveChanges();
            return(user);
        }
コード例 #4
0
        public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl)
        {
            string provider       = null;
            string providerUserId = null;

            if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId))
            {
                return(RedirectToAction("Manage"));
            }

            if (ModelState.IsValid)
            {
                // Insert a new user into the database
                using (FileManagerDAL db = new FileManagerDAL())
                {
                    UserProfile user = db.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == model.UserName.ToLower());
                    // Check if user already exists
                    if (user == null)
                    {
                        // Insert name into the profile table
                        db.UserProfiles.Add(new UserProfile {
                            UserName = model.UserName
                        });
                        db.SaveChanges();

                        OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName);
                        OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false);

                        return(RedirectToLocal(returnUrl));
                    }
                    else
                    {
                        ModelState.AddModelError("UserName", "User name already exists. Please enter a different user name.");
                    }
                }
            }

            ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName;
            ViewBag.ReturnUrl           = returnUrl;
            return(View(model));
        }