Example #1
0
        public ActionResult UserPreferencesEdit(UserPreferencesDTO usrPreferencesDTO, HttpPostedFileBase image)
        {
            var validImageTypes = new string[]
            {
                "image/gif",
                "image/jpeg",
                "image/pjpeg",
                "image/png"
            };

            if (image != null) //If no new file is being uploaded, then ignore image checks
            {
                if (image.ContentLength == 0)
                {
                    ModelState.AddModelError("ImageUpload", "This field is required");
                }
                else if (image.ContentLength > 102400)
                {
                    ModelState.AddModelError("ImageUpload", "File too large, maximum upload size is 100KB");
                }
                else if (!validImageTypes.Contains(image.ContentType))
                {
                    ModelState.AddModelError("ImageUpload", "Please choose either a GIF, JPG or PNG image.");
                }
                //get the bytes from the content stream of the file
                byte[] thePictureAsBytes = new byte[image.ContentLength];
                using (BinaryReader theReader = new BinaryReader(image.InputStream))
                {
                    thePictureAsBytes = theReader.ReadBytes(image.ContentLength);
                }
                usrPreferencesDTO.ImageData = thePictureAsBytes;
                usrPreferencesDTO.ImageType = image.ContentType;
            }

            if (ModelState.IsValid)
            {
                var userEmail = (HttpContext.User as WebUI.Common.CustomPrincipal).Email;

                //Replace with updated role
                using (HttpClientWrapper httpClient = new HttpClientWrapper(Session))
                {
                    var responseMessage = httpClient.PutAsJsonAsync("api/UserPreferencesAPI/" + usrPreferencesDTO.Id.ToString(), usrPreferencesDTO).Result;
                    responseMessage.EnsureSuccessStatusCode();
                    CacheManager.Instance.Remove(CacheManager.CACHE_KEY_USER_PREFS + userEmail);
                    return(RedirectToAction("UserPreferencesDetails"));
                }
            }
            return(View(usrPreferencesDTO));
        }
Example #2
0
        public static UserPreferencesDTO GetUserPreferences(string userEmail)
        {
            UserPreferencesDTO userPrefDTO = CacheManager.Instance.Get <UserPreferencesDTO>(CacheManager.CACHE_KEY_USER_PREFS + userEmail);

            if (userPrefDTO == null) //Not found in cache
            {
                using (UserPreferencesAPIController userPrefsAPI = new UserPreferencesAPIController())
                {
                    userPrefDTO = userPrefsAPI.GetPreferencesForUser(userEmail);
                    CacheManager.Instance.Add(CacheManager.CACHE_KEY_USER_PREFS + userEmail, userPrefDTO);
                }
            }

            return(userPrefDTO);
        }
Example #3
0
        /// <summary>
        /// To Update the Profile Picture of User
        /// </summary>
        /// <returns></returns>
        public ActionResult UploadProfileImage(string UploadedFile, string FileType)
        {
            byte[] ImageBinaryForm;
            using (HttpClientWrapper httpClient = new HttpClientWrapper(Session))
            {
                UserPreferencesDTO objProfile = new UserPreferencesDTO()
                {
                    ImageData = Convert.FromBase64String(UploadedFile),
                    ImageType = FileType
                };

                var updateProfileImage = httpClient.PostAsJsonAsync <UserPreferencesDTO>("api/UserProfileAPI/UpdateProfilePicture", objProfile).Result;
                ImageBinaryForm = JsonConvert.DeserializeObject <byte[]>(updateProfileImage.Content.ReadAsStringAsync().Result);
            }

            return(Json(new { Success = true, FileName = "data:image;base64," + Convert.ToBase64String(ImageBinaryForm) }, JsonRequestBehavior.AllowGet));
        }
Example #4
0
        private UserPreferencesDTO GetUserPreferences()
        {
            var userEmail = (HttpContext.User as WebUI.Common.CustomPrincipal).Email;

            UserPreferencesDTO userPrefDTO = CacheManager.Instance.Get <UserPreferencesDTO>(CacheManager.CACHE_KEY_USER_PREFS + userEmail);

            if (userPrefDTO == null) //Not found in cache
            {
                using (HttpClientWrapper httpClient = new HttpClientWrapper(Session))
                {
                    Task <String> response = httpClient.GetStringAsync("api/UserPreferencesAPI");
                    userPrefDTO = Task.Factory.StartNew(() => JsonConvert.DeserializeObject <UserPreferencesDTO>(response.Result)).Result;
                    CacheManager.Instance.Add(CacheManager.CACHE_KEY_USER_PREFS + userEmail, userPrefDTO);
                }
            }
            return(userPrefDTO);
        }
        public Byte[] PostUpdateProfilePicture([FromBody] UserPreferencesDTO FileName)
        {
            var email = HttpContext.Current.User.Identity.Name;

            UserProfile userProfile = db.UserProfiles.FirstOrDefault(usr => usr.Email == email);

            if (userProfile == null)
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            userProfile.UserPreferences.ImageData = FileName.ImageData;
            userProfile.UserPreferences.ImageType = FileName.ImageType;

            db.SaveChanges();

            return(userProfile.UserPreferences.ImageData);
        }
Example #6
0
        public static void BusinessRegisteredEmployee(string firstName, string busName, bool isExistingUser, string toAddress = null, string mobileNumber = null)
        {
            if (MessagingService.IsNotificationsEnabled)
            {
                if (isExistingUser)
                {
                    UserPreferencesDTO userPrefs = null;
                    if (!String.IsNullOrEmpty(toAddress))
                    {
                        userPrefs = MessagingService.GetUserPreferences(toAddress);
                    }

                    if (userPrefs.NotifyByEmail)
                    {
                        MailHelper.SendBusRegEmplMail(toAddress, firstName, busName, isExistingUser);
                    }
                    if (userPrefs.NotifyBySMS && !String.IsNullOrEmpty(mobileNumber))
                    {
                        SmsHelper.SendBusRegEmplSms(mobileNumber);
                    }
                    if (userPrefs.NotifyByApp)
                    {
                        using (NotificationsAPIController notificationController = new NotificationsAPIController())
                        {
                            //Send push notification
                            notificationController.Post(String.Format(ConfigurationManager.AppSettings.Get("mailBusRegExistingBody"), firstName, busName, ConfigurationManager.AppSettings.Get("ApiBaseURL")), toAddress)
                            .ContinueWith(t => Trace.TraceError("ERROR:" + t.Exception.ToString()), TaskContinuationOptions.OnlyOnFaulted);
                        }
                    }
                }
                else //New user, does not already exist in Rooster
                {
                    if (!String.IsNullOrEmpty(toAddress))
                    {
                        MailHelper.SendBusRegEmplMail(toAddress, firstName, busName, isExistingUser);
                    }

                    if (!String.IsNullOrEmpty(mobileNumber))
                    {
                        SmsHelper.SendBusRegEmplSms(mobileNumber);
                    }
                }
            }
        }
        public void Reset(int userId)
        {
            using (var session = Hibernate.SessionFactory.OpenSession())
            {
                var user        = session.QueryOver <User>().Where(u => u.Id == userId).SingleOrDefault();
                var preferences = session.QueryOver <UserPreference>().Where(p => p.User == user).SingleOrDefault();

                preferences.AutoRefreshingFrequency             = 600;
                preferences.DisplayOnlyTasksWithMyParticipation = true;
                preferences.DisplayTasksRefreshingProgressBar   = true;
                preferences.EnableTasksListAutoRefreshing       = true;
                preferences.HideCanceledTasks = true;
                preferences.TasksPerPage      = 50;

                Preferences = new UserPreferencesDTO(preferences);

                session.SaveOrUpdate(preferences);
                session.Flush();
            }
        }
        public HttpResponseMessage Put(Guid id, UserPreferencesDTO usrPrefDTO)
        {
            var         email      = HttpContext.Current.User.Identity.Name;
            UserProfile usrProfile = db.UserProfiles.FirstOrDefault(usr => usr.Email == email && usr.Id == id);

            if (usrProfile != null)
            {
                if (!ModelState.IsValid)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
                }
                try
                {
                    var userPreferences = db.UserPreferences.Find(usrPrefDTO.Id);

                    //If NULL, then retain any existing image data as no overrite is occurring (we don't pass back the whole image each time)
                    //This is a bit of a hack, best solution is to seperate out any uploaded documents as per this page (http://www.codeproject.com/Articles/658522/Storing-Images-in-SQL-Server-using-EF-and-ASP-NET)
                    if (usrPrefDTO.ImageData == null)
                    {
                        usrPrefDTO.ImageData = userPreferences.ImageData;
                        usrPrefDTO.ImageType = userPreferences.ImageType;
                    }

                    userPreferences = MapperFacade.MapperConfiguration.Map <UserPreferencesDTO, UserPreferences>(usrPrefDTO, userPreferences);

                    db.Entry(userPreferences).State = EntityState.Modified;

                    db.SaveChanges();
                }
                catch (DbUpdateConcurrencyException ex)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
                }

                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            else
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.Unauthorized));
            }
        }
        public void LoadPreferences(int userId)
        {
            using (var session = Hibernate.SessionFactory.OpenSession())
            {
                User           u  = null;
                UserPreference up = null;

                Preferences = session.QueryOver(() => up)
                              .JoinAlias(() => up.User, () => u)
                              .Where(() => u.Id == userId)
                              .SelectList(l => l
                                          .Select(() => u.Id)
                                          .Select(() => up.AutoRefreshingFrequency)
                                          .Select(() => up.TasksPerPage)
                                          .Select(() => up.DisplayOnlyTasksWithMyParticipation)
                                          .Select(() => up.EnableTasksListAutoRefreshing)
                                          .Select(() => up.DisplayTasksRefreshingProgressBar)
                                          .Select(() => up.HideCanceledTasks))
                              .TransformUsing(Transformers.AliasToBeanConstructor(typeof(UserPreferencesDTO).GetConstructors()[1]))
                              .SingleOrDefault <UserPreferencesDTO>();
            }
        }
 public void SavePreferences(UserPreferencesDTO preferences)
 {
     throw new NotImplementedException();
 }