Beispiel #1
0
        public ActionResult DeleteAll(int[] ids)
        {
            //1. Requirement when opening a transaction: Connection has to be opened
            FilesRepository fr = new FilesRepository();

            fr.MyConnection.Open();

            fr.MyTransaction = fr.MyConnection.BeginTransaction(); //from this point onwards all code executed against the db will remain pending

            try
            {
                new LoggingRepository().Logging("Deleting multiple elements");
                foreach (int id in ids)
                {
                    fr.DeleteFile(id);
                }

                fr.MyTransaction.Commit(); //Commit: you are confirming the changes in the db
            }
            catch (Exception ex)
            {
                //Log the exception on the cloud
                new LoggingRepository().ErrorLogging(ex);
                fr.MyTransaction.Rollback(); //Rollback: it will reverse all the changes done within the try-clause in the db
            }

            fr.MyConnection.Close();

            CacheRepository cr = new CacheRepository();

            cr.UpdateCache(fr.GetFiles(User.Identity.Name));

            return(RedirectToAction("Index"));
        }
Beispiel #2
0
 public void DeleteFile(FileSyncContent content)
 {
     _filesRepository.DeleteFile(new File
     {
         Data        = content.Data,
         Description = content.Description,
         FileContent = content.FileContent,
         FileName    = content.FileName,
         FileType    = content.FileType,
         Id          = content.Id,
         UserId      = content.UserId
     });
 }
Beispiel #3
0
        public ActionResult DeleteConfirmed(int id)
        {
            var file        = _filesRepository.GetFileById(id);
            var userProfile = _usersRepository.GetUserProfileByName(User.Identity.Name.ToLower());

            if (file == null || userProfile == null)
            {
                return(HttpNotFound());
            }

            if (file.UserId == userProfile.UserId)
            {
                _filesRepository.DeleteFile(file);
            }

            return(RedirectToAction("Index"));
        }
Beispiel #4
0
        public ActionResult Delete(int id)
        {
            try
            {
                new LoggingRepository().Logging("Deleting one element");
                FilesRepository fr = new FilesRepository();
                fr.DeleteFile(id);
                CacheRepository cr = new CacheRepository();
                cr.UpdateCache(fr.GetFiles(User.Identity.Name));
            }
            catch (Exception ex)
            {
                new LoggingRepository().ErrorLogging(ex);
            }

            return(RedirectToAction("Index"));
        }