Пример #1
0
        public PictureUser CreatePictureUser(string userName, string email, List <string> pictureId)
        {
            try
            {
                using (DocumentClient Client = new DocumentClient(new Uri(Context.EndpointUrl), Context.Authkey))
                {
                    _PictureUser = GetPictureUserByUserName(userName);

                    if (_PictureUser == null)
                    {
                        PictureUser newPictureUser = new PictureUser()
                        {
                            Username = userName, Email = email, PictureId = pictureId
                        };
                        Client.CreateDocumentAsync(Context.GetCollectionByName("PictureUsers").SelfLink, newPictureUser);
                        _PictureUser = GetPictureUserByUserName(userName);
                        return(newPictureUser);
                    }
                    else
                    {
                        return(_PictureUser);
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Пример #2
0
        public PictureUser UpdatePictureUserByUsername(string userName, string email, List <string> pictureId)
        {
            try
            {
                using (DocumentClient Client = new DocumentClient(new Uri(Context.EndpointUrl), Context.Authkey))
                {
                    _PictureUser = GetPictureUserByUserName(userName);

                    if (_PictureUser == null)
                    {
                        return(null);
                    }

                    Document document = GetDocumentById(_PictureUser.Id);
                    document.SetPropertyValue("Email", email);
                    document.SetPropertyValue("PictureId", pictureId);

                    Client.ReplaceDocumentAsync(document);

                    _PictureUser = GetPictureUserByUserName(userName);

                    return(_PictureUser);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Пример #3
0
        public PictureUser DeletePictureUserByUserName(string userName)
        {
            try
            {
                using (DocumentClient Client = new DocumentClient(new Uri(Context.EndpointUrl), Context.Authkey))
                {
                    _PictureUser = GetPictureUserByUserName(userName);
                    Document document = GetDocumentById(_PictureUser.Id);

                    if (_PictureUser == null)
                    {
                        return(null);
                    }

                    var result = Client.DeleteDocumentAsync(document.SelfLink);

                    if (result.Result == null)
                    {
                        return(null);
                    }

                    return(_PictureUser);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public JsonResult UploadDropZone(int?idAlbum)
        {
            string urlImage = "";

            try
            {
                if (idAlbum != null && idAlbum.GetValueOrDefault() > 0)
                {
                    var ctrlUI = new PictureUserDAL();
                    foreach (string fileName in Request.Files)
                    {
                        HttpPostedFileBase file = Request.Files[fileName];

                        if (file != null && file.ContentLength > 0)
                        {
                            var strDateTime = DateTime.Now.ToString("dd-MM-yyyy");
                            var fName       = idAlbum + "_" + Guid.NewGuid() + Path.GetExtension(file.FileName);
                            urlImage = string.Format("/UserImages/{0}/{1}/{2}/{3}/{4}", SysBaseInfor.GetCurrentUnitId(), SysBaseInfor.GetCurrentUserId(), SysBaseDirectory.pictureUploaded, strDateTime, fName);
                            var userPath = string.Format("{0}{1}/", userPictureUploadedPath, strDateTime);
                            if (!Directory.Exists(userPath))
                            {
                                Directory.CreateDirectory(userPath);
                            }
                            string path = Path.Combine(userPath, fName);
                            file.SaveAs(path);

                            var pictureSave = new PictureUser();
                            pictureSave.IdAlbum     = idAlbum.GetValueOrDefault();
                            pictureSave.IdUnit      = SysBaseInfor.GetCurrentUnitId().ToInt32();
                            pictureSave.CreatedBy   = SysBaseInfor.GetCurrentUserId();
                            pictureSave.CreatedAt   = DateTime.Now;
                            pictureSave.PictureUrl  = urlImage;
                            pictureSave.PictureName = fName;
                            ctrlUI.CreateItem(pictureSave);
                        }
                    }
                    return(Json(new { urlImage = urlImage }));
                }
                else
                {
                    return(Json("Có lỗi khi tải lên"));
                }
            }
            catch (Exception ex)
            {
                return(Json("Có lỗi khi tải lên"));
            }
        }
Пример #5
0
        public PictureUser GetPictureUserByUserName(string userName)
        {
            try
            {
                using (DocumentClient Client = new DocumentClient(new Uri(Context.EndpointUrl), Context.Authkey))
                {
                    _PictureUser = Client.CreateDocumentQuery <PictureUser>(Context.GetCollectionByName("PictureUsers").SelfLink)
                                   .Where(d => d.Username == userName).AsEnumerable().FirstOrDefault();

                    return(_PictureUser);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Пример #6
0
        public Picture RemoveExistingPictureToPictureUserByUserName(string UserName, string PictureName)
        {
            try
            {
                pictureUser = pictureUserController.GetPictureUserByUserName(UserName);
                picture     = pictureController.GetPictureByPictureName(PictureName);
                pictureUser.PictureId.Remove(picture.Id);

                PictureUser updatedPictureUser = pictureUserController.UpdatePictureUserByUsername(pictureUser.Username, pictureUser.Email, pictureUser.PictureId);

                return(picture);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Пример #7
0
        public PictureUser AddExistingPictureToPictureUserByUserName(string UserName, string PictureName)
        {
            try
            {
                using (DocumentClient Client = new DocumentClient(new Uri(Context.EndpointUrl), Context.Authkey))
                {
                    pictureUser = pictureUserController.GetPictureUserByUserName(UserName);
                    picture     = pictureController.GetPictureByPictureName(PictureName);
                    pictureUser.PictureId.Add(picture.Id);

                    PictureUser updatedPictureUser = pictureUserController.UpdatePictureUserByUsername(pictureUser.Username, pictureUser.Email, pictureUser.PictureId);

                    pictureUser = pictureUserController.GetPictureUserByUserName(UserName);

                    return(pictureUser);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Пример #8
0
        private void UpPhoto_Click(object sender, EventArgs e)
        {
            string User = UserLoginCache.UserId;

            try
            {
                openFileDialog1.Filter           = "Archivos jpg (*.jpg)|*.jpg";
                openFileDialog1.FilterIndex      = 1;
                openFileDialog1.RestoreDirectory = true;
                openFileDialog1.FileName         = "";
                if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    PictureUser.Load(this.openFileDialog1.FileName);

                    Pro.UpdateProfilePicture(User, PictureUser);
                }
            }
            catch (Exception ex)
            {
                ex.ToString();
                MessageBox.Show("No se pudo cargar la imagen de perfil");
            }
        }
Пример #9
0
        public IEnumerable <Picture> GetAllPicturesByUserName(string userName)
        {
            try
            {
                using (DocumentClient Client = new DocumentClient(new Uri(Context.EndpointUrl), Context.Authkey))
                {
                    pictureUser = pictureUserController.GetPictureUserByUserName(userName);

                    List <Picture> pictures = new List <Picture>();
                    foreach (var pictureId in pictureUser.PictureId)
                    {
                        pictures.Add(pictureController.GetPictureById(pictureId));
                    }


                    return(pictures);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Пример #10
0
 public PictureUser RemoveUser(string userName)
 {
     pictureUser = pictureUserController.DeletePictureUserByUserName(userName);
     return(pictureUser);
 }
Пример #11
0
 public PictureUser CreateUser(string userName, string email, List <string> pictureId)
 {
     pictureUser = pictureUserController.CreatePictureUser(userName, email, pictureId);
     return(pictureUser);
 }
Пример #12
0
 public PictureUser CheckpictureUser(string userName)
 {
     pictureUser = pictureUserController.GetPictureUserByUserName(userName);
     return(pictureUser);
 }