public ActionResult Register(ViewRegister data)
        {
            User nuser = ctx.Users.Where(u => u.Login == data.Login).FirstOrDefault();

            if (ModelState.IsValid && nuser == null)
            {
                nuser          = new User();
                nuser.Name     = data.Name;
                nuser.Email    = data.Email;
                nuser.Login    = data.Login;
                nuser.Country  = ctx.Countries.Find(data.CountryID);
                nuser.City     = ctx.Cities.Where(c => c.ID == data.CityID).FirstOrDefault();
                nuser.Salt     = SecurityHandler.GetSalt();
                nuser.Password = SecurityHandler.GetHash(data.Password, nuser.Salt);
                nuser.AboutMe  = data.About;
                ctx.Users.Add(nuser);
                ctx.SaveChangesAsync();
                Session["Name"]    = nuser.Name;
                Session["Email"]   = nuser.Email;
                Session["Login"]   = nuser.Login;
                Session["Country"] = nuser.Country.Name;
                Session["City"]    = nuser.City.CityName;
                Session["About"]   = nuser.AboutMe;
                return(RedirectToAction("Logged", "Home"));
            }
            else if (nuser != null)
            {
                ModelState.AddModelError("", "User already exist");
            }
            else
            {
                ModelState.AddModelError("", "You wrong somewhere");
            }
            ViewBag.ListCountries = new SelectList(ctx.Countries, "ID", "Name");
            ViewBag.ListCities    = new SelectList(ctx.Cities.Where(c => c.Country.ID == data.CountryID), "ID", "CityName");
            return(PartialView(data));
        }
示例#2
0
        public async Task <ActionResult> EditThumbnailConfirm(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Picture pic = ctx.Pictures.Find(id);

            if (pic == null)
            {
                return(HttpNotFound());
            }
            pic.Album.ThumbnailURL = pic.URLpath;
            ctx.Entry(pic).State   = System.Data.Entity.EntityState.Modified;
            await ctx.SaveChangesAsync();

            return(Json("ok"));
        }