Exemplo n.º 1
0
        public ActionResult CreateGroup(string name)
        {
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(getLocale());
            ViewBag.Localize = getLocale();
            int idToRedirect = 0;

            using (var transaction = _entities.Database.BeginTransaction())
            {
                try
                {
                    if (name == null || name.Length == 0)
                    {
                        throw new Exception(Resources.Resource.ERR_EMPTY_FIELD);
                    }
                    var group = new PersonGroup();
                    group.Name = name;

                    ApplicationUser user = System.Web.HttpContext.Current.GetOwinContext().GetUserManager <ApplicationUserManager>().FindById(User.Identity.GetUserId <int>());
                    if (user != null)
                    {
                        if (_entities.PersonGroups.Where(w => w.Name == name && w.PersonId == user.Id).Any())
                        {
                            throw new Exception(Resources.Resource.ERR_GROUP_ALREDY);
                        }
                        var email = user.Email;
                        group.PersonId = _entities.People.Where(w => w.Email == email).Select(s => s.Id).FirstOrDefault();
                    }
                    else
                    {
                        group.PersonId = null;
                    }
                    _entities.PersonGroups.Add(group);
                    _entities.SaveChanges();
                    idToRedirect = group.Id;
                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    TempData["MessageContent"] = ex.Message;
                }
            }
            return(RedirectToAction("Partial_GroupsAndEmails", new { selectedId = idToRedirect, lang = getLocale() }));
        }
Exemplo n.º 2
0
        public ActionResult SetAvatar(HttpPostedFileBase file)
        {
            ViewBag.Localize = getLocale();
            if (file != null)
            {
                using (var transaction = _entities.Database.BeginTransaction())
                {
                    try
                    {
                        var             avatarFile = "";
                        ApplicationUser user       = System.Web.HttpContext.Current.GetOwinContext().GetUserManager <ApplicationUserManager>().FindById(User.Identity.GetUserId <int>());
                        if (user != null)
                        {
                            var email  = user.Email;
                            var person = _entities.People.Where(w => w.Email == email).FirstOrDefault();
                            if (person.AvatarFile != null)
                            {
                                try
                                {
                                    System.IO.File.Delete(Server.MapPath("/avatars/") + avatarFile + "_128");
                                    System.IO.File.Delete(Server.MapPath("/avatars/") + avatarFile + "_50");
                                }
                                catch { }
                            }
                            person.AvatarFile = _stringGenerator.Next();
                            avatarFile        = person.AvatarFile;
                            _entities.SaveChanges();
                        }
                        var bitmap = new Bitmap(file.InputStream);

                        var bitmap128 = _imageCompressor.Compress(bitmap, new Size(128, 128));
                        var path      = Server.MapPath("/avatars/") + avatarFile + "_128.png";
                        bitmap128.Save(path, ImageFormat.Png);
                        var bitmap25 = _imageCompressor.Compress(bitmap, new Size(50, 50));
                        path = Server.MapPath("/avatars/") + avatarFile + "_50.png";
                        bitmap25.Save(path, ImageFormat.Png);
                        ViewBag.Avatar_128      = getUserAvatar(avatarFile + "_128");
                        ViewBag.PeopleForMaster = _entities.People.Select(s => s).ToList();
                        transaction.Commit();
                    }
                    catch (Exception)
                    {
                        transaction.Rollback();
                        return(RedirectToAction("Message", "Home", new { lang = getLocale() }));
                    }
                }
            }
            ViewBag.Email = EMAIL;
            AVATAR        = ViewBag.Avatar_128;
            return(RedirectToAction("UserProfile"));
        }
Exemplo n.º 3
0
        public async Task <ActionResult> ConfirmEmail(int userId, string code, string lang = "en")
        {
            ViewBag.Localize = getLocale();

            if (userId == default(int) || code == null)
            {
                return(View("Error"));
            }
            var result = await UserManager.ConfirmEmailAsync(userId, code);

            if (result.Succeeded)
            {
                using (var entities = new ScreenTakerEntities())
                {
                    var defaultFolder = new Folder()
                    {
                        IsPublic     = true,
                        OwnerId      = userId,
                        SharedCode   = _stringGenerator.Next(),
                        Name         = "Public",
                        CreationDate = DateTime.Now
                    };
                    entities.Folders.Add(defaultFolder);
                    var user = entities.People.Find(userId);
                    if (user != null)
                    {
                        var userShares = entities.UserShares.Where(w => w.Email == user.Email);
                        foreach (var u in userShares)
                        {
                            u.PersonId = user.Id;
                        }
                    }
                    entities.SaveChanges();
                }
                return(View("ConfirmEmail"));
            }
            AddErrors(result);
            ViewBag.Email = UserManager.FindById(userId).Email;
            EMAIL         = ViewBag.Email;
            return(View());
        }