示例#1
0
 public BaseController()
 {
     DbContext   = new ApplicationDbContext();
     Context     = new MindCornersEntities();
     UserManager = new ApplicationUserManager(new UserStore <ApplicationUser>(DbContext));
     //_userProfileRepository = new UserProfileRepository(Context, DbUser, null);
 }
示例#2
0
        public static void AddNotification(Guid senderUserId, Guid recieverUserId, Guid sourceId, int type, string body)
        {
            using (MindCornersEntities context = new MindCornersEntities())
                using (NotificationRepository notificationRepository = new NotificationRepository(context, senderUserId, null))
                    using (UserProfileRepository userProfileRepository = new UserProfileRepository(context, senderUserId, null))
                    {
                        //var senderUser = userProfileRepository.GetById(senderUserId);

                        notificationRepository.Create(new Notification()
                        {
                            SenderId = senderUserId,
                            UserId   = recieverUserId,
                            SourceId = sourceId,
                            Type     = type,
                            Body     = body,
                        });

                        try
                        {
                            notificationRepository.SaveChanges();
                        }
                        catch (Exception e)
                        {
                            LogHelper.WriteError(e);
                        }
                    }
        }
示例#3
0
 public BaseController()
 {
     Context    = new MindCornersEntities();
     Serializer = new JavaScriptSerializer();
     //Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator = Thread.CurrentThread.CurrentCulture.NumberFormat.CurrencyDecimalSeparator = Thread.CurrentThread.CurrentCulture.NumberFormat.PercentDecimalSeparator = ".";
     //Thread.CurrentThread.CurrentCulture.DateTimeFormat.FullDateTimePattern = "dd/MM/yyyy HH:mm:ss";
     //Thread.CurrentThread.CurrentCulture.DateTimeFormat.DateSeparator = "/";
 }
        public GenericRepository(MindCornersEntities context, Guid currentUserId, Guid?currentUserOrganizationId, bool createObjectSet = true)
            : base(currentUserId, context, currentUserOrganizationId)
        {
            if (createObjectSet)
            {
                _objectSet = ((IObjectContextAdapter)Context).ObjectContext.CreateObjectSet <TEntity>();
            }

            ((IObjectContextAdapter)Context).ObjectContext.ContextOptions.LazyLoadingEnabled = true;
        }
        public FileResult GetProfileImage(Guid userId)
        {
            using (MindCornersEntities context = new MindCornersEntities())
                using (UserProfileRepository userProfileRepository = new UserProfileRepository())
                {
                    var user = userProfileRepository.GetById(userId);
                    if (user != null)
                    {
                        return(GetProfileImageByName(user.ProfileImageString));
                    }

                    return(null);
                }
        }
示例#6
0
        public static MessageTemplate GetMessageTemplateWithReplacedBody(MessageTemplateTypes messageTemplateType, Dictionary <string, string> values)
        {
            using (MindCornersEntities context = new MindCornersEntities())
                using (MessageTemplateRepository messageTemplateRepository = new MessageTemplateRepository(context, Guid.Empty, null))
                {
                    var messageTemplate = messageTemplateRepository.GetMessageTemplateByType(messageTemplateType);
                    if (messageTemplate != null)
                    {
                        StringBuilder sb = new StringBuilder(messageTemplate.Body);
                        foreach (var value in values)
                        {
                            sb.Replace(value.Key, value.Value);
                        }
                        messageTemplate.BodyReplaced = sb.ToString();
                        return(messageTemplate);
                    }
                }

            return(null);
        }
 public SynchronizableGenericRepository(MindCornersEntities context, Guid currentUserId, Guid?currentUserOrganizationId) : base(context, currentUserId, currentUserOrganizationId)
 {
 }
        public async Task <ActionResult> ExternalLoginCallback(string returnUrl)
        {
            var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();

            if (loginInfo == null)
            {
                return(RedirectToAction("Login"));
            }

            string firstName  = string.Empty;
            string lastName   = string.Empty;
            string middleName = string.Empty;
            string email      = string.Empty;
            string puctureUrl = string.Empty;

            if (loginInfo.Login.LoginProvider == "Facebook")
            {
                var     identity     = AuthenticationManager.GetExternalIdentity(DefaultAuthenticationTypes.ExternalCookie);
                var     access_token = identity.FindFirstValue("FacebookAccessToken");
                var     fb           = new FacebookClient(access_token);
                dynamic myInfo       = fb.Get("/me?fields=first_name,middle_name,last_name,id,email,picture.width(200)"); // specify the email field
                loginInfo.Email = myInfo.email;
                puctureUrl      = GetFacebookImageUrl(myInfo);
            }
            var loginInf = new ExternalLoginInfo()
            {
            };

            //  var firstNameClaim = loginInfo.ExternalIdentity.Claims.First(c => c.Type == "urn:facebook:first_name");

            // Sign in the user with this external login provider if the user already has a login
            var result = await SignInManager.ExternalSignInAsync(loginInfo, isPersistent : false);

            switch (result)
            {
            case SignInStatus.Success:
            {
                var test = GetProfilePicture(puctureUrl);

                //    using (MindCornersEntities context = new MindCornersEntities())
                //{
                //    var user = context.UserProfiles.FirstOrDefault(p => p.User_Id == User.Identity.GetUserId());
                //    if (user != null)
                //    {
                //        user.ProfileImage = GetProfilePicture(puctureUrl);
                //        context.SaveChanges();
                //    }
                //}

                return(RedirectToLocal(returnUrl));
            }

            case SignInStatus.LockedOut:
                return(View("Lockout"));

            case SignInStatus.RequiresVerification:
                return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = false }));

            case SignInStatus.Failure:
            default:
            {
                using (MindCornersEntities context = new MindCornersEntities())
                {
                    var invitation = context.Invitations.FirstOrDefault(p => p.Email == loginInfo.Email && p.ExpireDate > DateTime.Now && p.DateDeleted == null);
                    if (invitation != null)
                    {
                        return(View("RegisterActivationCode", new Invitation()
                            {
                                Email = loginInfo.Email, IsExternalUserLogin = true
                            }));
                    }
                    else
                    {
                        return(View("ExternalLoginFailure"));
                    }
                }

                // If the user does not have an account, then prompt the user to create an account


                //ViewBag.ReturnUrl = returnUrl;
                //ViewBag.LoginProvider = loginInfo.Login.LoginProvider;
                //return View("ExternalLoginConfirmation", new ExternalLoginConfirmationViewModel { Email = loginInfo.Email });
            }
            }
        }
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                using (var txscope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
                {
                    try
                    {
                        var user = new ApplicationUser
                        {
                            UserName    = model.Email,
                            Email       = model.Email,
                            UserProfile =
                                new UserProfile()
                            {
                                Id        = Guid.NewGuid(),
                                FirstName = model.FirstName,
                                LastName  = model.LastName
                            }
                        };

                        var result = await UserManager.CreateAsync(user, model.Password);

                        if (result.Succeeded)
                        {
                            using (MindCornersEntities context = new MindCornersEntities())
                            {
                                var invitation = context.Invitations.FirstOrDefault(p => p.Id == InvitationId);
                                if (invitation != null)
                                {
                                    var role = DbContext.Roles.FirstOrDefault(p => p.Id == invitation.RoleId.ToString());
                                    await this.UserManager.AddToRoleAsync(user.Id, role.Name);

                                    invitation.State     = (int)InvitationStates.Accepted;
                                    invitation.StateDate = DateTime.Now;
                                    try
                                    {
                                        context.SaveChanges();
                                        IsAuthenticationCodeValid = false;
                                        InvitationId = null;

                                        if (Request.Files.Count > 0)
                                        {
                                            var file = Request.Files[0];

                                            if (file != null && file.ContentLength > 0)
                                            {
                                                var fileExtention = Path.GetExtension(file.FileName);

                                                var fileFullName = Utilities.UploadBlob("profile-images", string.Format("{0}{1}", Guid.NewGuid(), fileExtention),
                                                                                        file.InputStream);

                                                user.UserProfile.ProfileImageString = fileFullName;
                                            }
                                        }
                                    }
                                    catch (Exception e)
                                    {
                                        Console.WriteLine(e);
                                    }

                                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                                    // 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>");

                                    txscope.Complete();
                                    return(RedirectToAction("Index", "Home"));
                                }
                            }
                        }

                        AddErrors(result);
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
 public DisposableRepository()
 {
     Context = new MindCornersEntities();
 }
 public DisposableRepository(Guid currentUserId)
 {
     CurrentUserId = currentUserId;
     Context       = new MindCornersEntities();
 }
 public DisposableRepository(Guid currentUserId, MindCornersEntities context, Guid?currentUserOrganizationId)
 {
     CurrentUserId             = currentUserId;
     Context                   = context;
     CurrentUserOrganizationId = currentUserOrganizationId;
 }