public Addresses GetAddress(short id)
 {
     using (var entityContext = new SiteDBEntities())
     {
         var address = entityContext.Addresses
                       .Where(a => a.Id == id)
                       .ProjectTo <AddressDTO>()
                       .FirstOrDefault();
         return(address);
     }
 }
        public ActionResult Register(RegisterModel model)
        {
#if DEBUG
            using (SiteDBEntities db = new SiteDBEntities(true))
#else
            using (SiteDBEntities db = new SiteDBEntities(false))
#endif
            {
                if (db.Users.Any(s => s.Email.ToLower() == model.Email.ToLower()))
                {
                    ModelState.AddModelError("", "Email already exists");
                }
            }

            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {
                    string token = WebSecurity.CreateUserAndAccount(model.UserName, model.Password, propertyValues: new
                    {
                        Email = model.Email
                    }, requireConfirmationToken: true);


                    string confirmationLink = Url.Action("confirm", "account", new { code = token }, Request.Url.Scheme);
                    string emailBodyText    =
                        "<p>Thank you for signing up with us! "
                        + "Please confirm your registration by clicking the following link:</p>"
                        + "<p><a href=\"" + confirmationLink + "\">Click to confirm your registration</a></p>"
                        + "<p>If the link does not work, copy and paste this url into your browser:<br/><strong> "
                        + confirmationLink
                        + "</strong></p>";

                    Globals.SendEmail(model.Email, "Your account confirmation", emailBodyText);


                    ViewBag.Emailed = model.Email;
                    model           = null;
                    return(View(model));
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Fetch Posts from server to our SQL DB
        /// </summary>
        /// <returns>
        /// Number of rows that changed
        /// </returns>
        private static async Task <int> FetchPosts()
        {
            List <Posts> posts = JsonConvert.DeserializeObject <List <Posts> >(await HttpRequestsManager.ExecuteRequestAsync(POSTS_URL));


            using (SiteDBEntities db = new SiteDBEntities())
            {
                foreach (Posts post in posts)
                {
                    if (!db.Posts.Any(u => u.id == post.id))
                    {
                        db.Posts.Add(post);
                    }
                }
                return(db.SaveChanges());
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Fetch Users from server to our SQL DB
        /// </summary>
        /// <returns>
        /// Number of rows that changed
        /// </returns>
        private static async Task <int> FetchUsers()
        {
            List <JToken> tokens = JArray.Parse(await HttpRequestsManager.ExecuteRequestAsync(USERS_URL)).ToList();

            using (SiteDBEntities db = new SiteDBEntities())
            {
                foreach (JToken token in tokens)
                {
                    int id = (int)token["id"];
                    if (!db.Users.Any(u => u.Id == id))
                    {
                        db.Users.Add(Users.CreateUser(token));
                    }
                }

                return(db.SaveChanges());
            }
        }
Exemplo n.º 5
0
 public GenericRepository(SiteDBEntities context)
 {
     this.context = context;
     this.dbSet   = context.Set <TEntity>();
 }
 public ListingRepository(SiteDBEntities db)
 {
     this.db = db;
 }