Exemple #1
0
        public ActionResult Settings(ChangesToProfile model)
        {
            account acc = db.account.Find(User.Identity.GetUserId());

            if (model.firstname != null)
            {
                db.Entry(acc).Property(u => u.firstname).CurrentValue = model.firstname;
            }
            if (model.lastname != null)
            {
                db.Entry(acc).Property(u => u.lastname).CurrentValue = model.lastname;
            }
            if (model.birthday != null)
            {
                db.Entry(acc).Property(u => u.birthday).CurrentValue = model.birthday;
            }
            if (model.description != null)
            {
                db.Entry(acc).Property(u => u.description).CurrentValue = model.description;
            }
            if (model.ImageUpload != null)
            {
                Cloudinary cloudinary   = new CloudinaryAccount().Cloud;
                var        uploadParams = new ImageUploadParams()
                {
                    File = new CloudinaryDotNet.Actions.FileDescription(model.ImageUpload.FileName,
                                                                        model.ImageUpload.InputStream)
                };
                var uploadResult = cloudinary.Upload(uploadParams);
                db.Entry(acc).Property(u => u.profilePic).CurrentValue = uploadResult.PublicId;
            }

            try
            {
                db.SaveChanges();
            }
            catch (DbEntityValidationException e) {
                return(View(model));
            }
            return(RedirectToAction("Profile", "Account", new { idUser = acc.UserId }));
        }
Exemple #2
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email, Hometown = null
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    account acc = new account
                    {
                        UserId      = user.Id,
                        firstname   = model.firstname,
                        lastname    = model.lastname,
                        Email       = model.Email,
                        birthday    = model.birthday,
                        description = model.description
                    };
                    if (model.description == null)
                    {
                        acc.description = "Profile is still under construction";
                    }

                    if (model.ImageUpload != null)
                    {
                        Cloudinary cloudinary   = new CloudinaryAccount().Cloud;
                        var        uploadParams = new ImageUploadParams()
                        {
                            File = new CloudinaryDotNet.Actions.FileDescription(model.ImageUpload.FileName,
                                                                                model.ImageUpload.InputStream)
                        };
                        var uploadResult = cloudinary.Upload(uploadParams);

                        acc.profilePic = uploadResult.PublicId;
                    }
                    else
                    {
                        acc.profilePic = "sample";
                    }

                    db.account.Add(acc);
                    try
                    {
                        db.SaveChanges();
                    }
                    catch (DbEntityValidationException e)
                    {
                        foreach (var eve in e.EntityValidationErrors)
                        {
                            System.Diagnostics.Debug.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                                               eve.Entry.Entity.GetType().Name, eve.Entry.State);
                            foreach (var ve in eve.ValidationErrors)
                            {
                                System.Diagnostics.Debug.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                                                   ve.PropertyName, ve.ErrorMessage);
                            }
                        }
                        throw;
                    }
                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Exemple #3
0
        public ActionResult FileUpload(EventCreateViewModel model)
        {
            Event ev = new Event();

            model.EventBeginDate = model.EventBeginDate.Add(model.EventBeginTime.Value.TimeOfDay);
            model.EventEndDate   = model.EventEndDate.Add(model.EventEndTime.Value.TimeOfDay);
            ev.EventName         = model.EventName;
            ev.EventParticipants = 1;
            ev.EventDescription  = model.EventDescription;
            ev.EventBeginDate    = model.EventBeginDate;
            ev.EventEndDate      = model.EventEndDate;
            ev.EventLocation     = model.EventLocation;
            ev.EventPrice        = model.EventPrice;
            if (model.ImageUpload != null)
            {
                Cloudinary cloudinary   = new CloudinaryAccount().Cloud;
                var        uploadParams = new ImageUploadParams()
                {
                    File = new CloudinaryDotNet.Actions.FileDescription(model.ImageUpload.FileName,
                                                                        model.ImageUpload.InputStream)
                };
                var uploadResult = cloudinary.Upload(uploadParams);

                ev.EventPicture = uploadResult.PublicId;
            }
            else
            {
                ev.EventPicture = "sample";
            }
            db.Event.Add(ev);
            try
            {
                db.SaveChanges();
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    System.Diagnostics.Debug.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                                       eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        System.Diagnostics.Debug.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                                           ve.PropertyName, ve.ErrorMessage);
                    }
                }
                throw;
            }

            logboek lb = new logboek
            {
                UserID     = User.Identity.GetUserId(),
                EventID    = db.Event.Where(e => e.EventName == ev.EventName && e.EventDescription == ev.EventDescription && e.EventPicture == ev.EventPicture).Select(t => t.EventId).First(),
                Organize   = true,
                Interested = false,
                Going      = true
            };

            //split input tags
            string[] tags = model.TagName.Split(new string[] { ", " }, StringSplitOptions.None);
            for (int i = 0; i < tags.Length; i++)
            {
                //make all tags
                Tag tag = new Tag();
                tag.TagName = tags[i];
                tag.EventId = lb.EventID;
                //add binding EventId - tagName to database
                db.Tag.Add(tag);
            }

            db.logboek.Add(lb);
            try
            {
                db.SaveChanges();
            }
            catch (DbEntityValidationException e)
            {
                //Dit is gewoon test code indien het niet werkte
                return(RedirectToAction("Index", "Home"));
            }
            return(RedirectToAction("EventDetails", "Event", new { id = ev.EventId }));
            // after successfully uploading redirect the user
        }