예제 #1
0
        public JsonResult AddDreams(DreamCustom model)
        {
            CheckConnection();

            if (ModelState.IsValid)
            {
                int User_Id = Convert.ToInt32(Session["UserId"]);
                var dream   = new Dream();
                dream.Title       = model.Title;
                dream.Description = model.Description;
                dream.Lat         = model.Lat;
                dream.Long        = model.Long;
                dream.RealLat     = model.Lat;
                dream.RealLong    = model.Long;
                dream.isPublic    = model.isPublic;
                dream.CreateDate  = model.CreateDate;
                dream.UserID      = User_Id;
                dream.Lang        = model.Lang;
                foreach (var cat in model.Categories)
                {
                    dream.DreamAndCategories.Add(new DreamAndCategory()
                    {
                        CategoryID = cat
                    });
                }
                foreach (var tag in model.Tags)
                {
                    var _tag = _db.Tags.Add(new Tag()
                    {
                        Name = tag
                    });
                    dream.DreamAndTags.Add(new DreamAndTag()
                    {
                        Tag = _tag
                    });
                }
                _db.Dreams.Add(dream);
                _db.SaveChanges();
                return(Json(true, JsonRequestBehavior.AllowGet));
            }
            else
            {
                var errors = ModelState.Select(x => x.Value.Errors.Select(e => e.ErrorMessage));
                return(Json(errors, JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult Confirmation(string id)
        {
            CheckConnection();
            Unconfirmed_Users user = _db.Unconfirmed_Users.Where(x => x.ConfirmationCode == id).FirstOrDefault();

            _db.Users.Add(new User()
            {
                UserName = user.Username,
                Email = user.Email,
                Password = user.Password,
                Secret = Random32(),
                isFbUser = false,
                Lang=user.Lang,
                CreateDate=DateTime.Now,
            });
            _db.SaveChanges();

            _db.Unconfirmed_Users.RemoveRange(_db.Unconfirmed_Users.Where(x => x.Email == user.Email));
            _db.SaveChanges();

            return View();
        }