public async Task <IHttpActionResult> Register(RegisterBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var user = new ApplicationUser {
                UserName = model.Email, Email = model.Email
            };

            var result = await UserManager.CreateAsync(user, model.Password);

            if (!result.Succeeded)
            {
                return(GetErrorResult(result));
            }
            VtaDbContext dbContext = Request.GetOwinContext().Get <VtaDbContext>();

            dbContext.Students.Add(new Student()
            {
                Id         = user.Id,
                Name       = user.UserName,
                Created    = DateTime.Now,
                CreatedBy  = user.Id,
                Modified   = DateTime.Now,
                ModifiedBy = user.Id
            });
            dbContext.SaveChanges();
            return(Ok());
        }
Beispiel #2
0
        public async Task <ActionResult> Create(FileUploadViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (model.ImageUpload != null && model.ImageUpload.ContentLength > 0)
                {
                    VtaDbContext db   = new VtaDbContext();
                    var          file = await db.Files.FindAsync(model.FileId);

                    string extension = Path.GetExtension(model.ImageUpload.FileName);
                    await AzureHelper.CreateAndConfigureAsync();

                    HttpPostedFileBase photoToUpload = model.ImageUpload;
                    string             name          = file.Id + extension;
                    string             url           = await AzureHelper.UploadPhotoAsync(photoToUpload, name);

                    file.SourceUrl       = url;
                    file.IsUploaded      = true;
                    file.ConvertedUrl    = "";
                    file.IsConverted     = false;
                    db.Entry(file).State = EntityState.Modified;
                    db.SaveChanges();
                }

                return(RedirectToAction("Index", "Files"));
            }
            return(View(model));
        }