示例#1
0
        public ActionResult Create([Bind(Include = "Id,Name,Website")] Company company)
        {
            if (ModelState.IsValid)
            {
                db.Companies.Add(company);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(company));
        }
        public IActionResult Upload(FileUploadViewModel pvm)
        {
            FileModel file = new FileModel();

            if (pvm.UploadedFile != null)
            {
                byte[] fileBytes = null;

                // считываем переданный файл в массив байтов
                using (var binaryReader = new BinaryReader(pvm.UploadedFile.OpenReadStream()))
                {
                    fileBytes = binaryReader.ReadBytes((int)pvm.UploadedFile.Length);
                }
                // установка массива байтов
                file.Content = fileBytes;
                file.Path    = pvm.UploadedFile.FileName;
            }
            _context.Files.Add(file);
            try
            {
                _context.SaveChanges();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.InnerException.Message);
            }
            return(RedirectToAction("Index"));
        }
示例#3
0
        public async Task <UserViewModel> SetUserImage(IFormFile file, string userID)
        {
            User user = await _users.FindByIdAsync(userID);

            if (user.PhotoID != 1)
            {
                _files.Files.Remove(_files.Files.FirstOrDefault(f => f.Id == user.PhotoID));
                _files.SaveChanges();
            }
            var model = _files.SaveFile(file);

            user.PhotoID = model.Id;
            await _users.UpdateAsync(user);

            return(new UserViewModel
            {
                Id = user.Id,
                Photo = new ImageData
                {
                    ImageBinary = model.Data,
                    ImageHeaders = model.ContentType
                },
                UserName = user.Name
            });
        }
        public ActionResult Create([Bind(Include = "Id,Name,Premium,Deductible,CoInsurance,CoPay,InsuranceType,CompanyId,UserId")] Policy policy)
        {
            if (ModelState.IsValid)
            {
                db.Policies.Add(policy);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CompanyId = new SelectList(db.Companies, "Id", "Name", policy.CompanyId);
            ViewBag.UserId    = new SelectList(db.AppUsers, "Id", "FullName", policy.AppUserId);



            return(View(policy));
        }
        // GET: Contacts
        public async Task <ActionResult> Index()
        {
            IEnumerable <Contact> selectedContacts = Enumerable.Empty <Contact>();

            try
            {
                selectedContacts = await SalesforceService.MakeAuthenticatedClientRequestAsync(
                    async (client) =>
                {
                    QueryResult <Contact> contacts =
                        await client.QueryAsync <Contact>("SELECT Id, Salutation, FirstName, LastName, MailingCity, MailingState, MailingCountry From Contact");

                    return(contacts.Records);
                }
                    );

                foreach (var item in selectedContacts)
                {
                    db.Contacts.Add(item);
                }
                db.SaveChanges();
                db.Dispose();
            }
            catch (Exception e)
            {
                this.ViewBag.OperationName    = "query Salesforce Contacts";
                this.ViewBag.AuthorizationUrl = SalesforceOAuthRedirectHandler.GetAuthorizationUrl(this.Request.Url.ToString());
                this.ViewBag.ErrorMessage     = e.Message;
            }
            if (this.ViewBag.ErrorMessage == "AuthorizationRequired")
            {
                return(Redirect(this.ViewBag.AuthorizationUrl));
            }
            return(View(selectedContacts));
        }
示例#6
0
        private void RemoveButton_Click(object sender, EventArgs e)
        {
            if (watcherListView.SelectedItems.Count == 0)
            {
                return;
            }
            var item = watcherListView.SelectedItems[0];
            var id   = (int)item.Tag;

            using (var ctx = new FilesContext())
            {
                Watcher found = ctx.Watchers.SingleOrDefault(watcher => watcher.Id == id);
                if (found == null)
                {
                    Console.Write($"Could not find watcher with id {id}.");
                    return;
                }
                var confirmResult = MessageBox.Show(
                    $"Are you sure you want to delete this watcher? This will delete all custom tags and command for files in:\n{found.Directory}",
                    "Confirmation",
                    MessageBoxButtons.YesNo,
                    MessageBoxIcon.Warning
                    );
                if (confirmResult != DialogResult.Yes)
                {
                    return;
                }
                ctx.Watchers.Remove(found);
                ctx.SaveChanges();
                Monitor.Stop(found);
            }
            RefreshListView();
        }
 public ActionResult Create([Bind(Include = "Id,FirstName,LastName,Age")] AppUser user)
 {
     try
     {
         if (ModelState.IsValid)
         {
             db.AppUsers.Add(user);
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
     }
     catch (DataException)
     {
         ModelState.AddModelError("", "Unable to save changes.  Try again, and if the problem persists see your system Administrator");
     }
     return(View(user));
 }
示例#8
0
 public void InsertFile(File file)
 {
     using (var context = new FilesContext())
     {
         context.Fisiere.Add(file);
         context.SaveChanges();
     }
 }
示例#9
0
 public void DeleteFile(File file)
 {
     using (var context = new FilesContext())
     {
         context.Fisiere.Attach(file);
         context.Fisiere.Remove(file);
         context.SaveChanges();
     }
 }
示例#10
0
        public void EditFile(File file)
        {
            using (var context = new FilesContext())
            {
                var oldFile = context.Fisiere.FirstOrDefault(c => c.Id == file.Id);

                if (oldFile != null)
                {
                    oldFile.Data        = file.Data;
                    oldFile.FileContent = file.FileContent;
                    oldFile.FileType    = file.FileType;
                    oldFile.Description = file.Description;
                    oldFile.FileName    = file.FileName;
                }

                context.SaveChanges();
            }
        }
示例#11
0
        //Все загружаемые файлы в ASP.NET Core представлены типом IFormFile из пространства
        //имен Microsoft.AspNetCore.Http.


        public async Task <IActionResult> AddFile(IFormFile uploadedFile, CategoryDTO category)
        {
            if (uploadedFile != null)
            {
                // путь к папке Files
                string path = "/Files/" + uploadedFile.FileName;
                // сохраняем файл в папку Files в каталоге wwwroot
                // using (var fileStream = new FileStream(_appEnvironment.WebRootPath + path, FileMode.Create))
                using (var fileStream = new FileStream(_appEnvironment.ContentRootPath + path, FileMode.Create))
                {
                    await uploadedFile.CopyToAsync(fileStream);
                }
                FileModel file = new FileModel {
                    Name = uploadedFile.FileName, Path = path
                };
                _context.Files.Add(file);
                _context.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
示例#12
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 (var db = new FilesContext())
                {
                    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));
        }
示例#13
0
        public IActionResult Create(PersonViewModel pvm)
        {
            Person person = new Person {
                Name = pvm.Name
            };

            if (pvm.Avatar != null)
            {
                byte[] imageData = null;
                // считываем переданный файл в массив байтов
                using (var binaryReader = new BinaryReader(pvm.Avatar.OpenReadStream()))
                {
                    imageData = binaryReader.ReadBytes((int)pvm.Avatar.Length);
                }
                // установка массива байтов
                person.Avatar = imageData;
            }
            _filesContext.People.Add(person);
            _filesContext.SaveChanges();

            return(RedirectToAction("Index2"));
        }
示例#14
0
 public FileDetailsModel PostFileDetails(FileDetailsModel fileDetails)
 {
     _context.FileDetails.Add(fileDetails);
     _context.SaveChanges();
     return(GetFileDetails(fileDetails.FileId));
 }