Ejemplo n.º 1
0
        public ActionResult EditProfile(EditProfileViewModel model, HttpPostedFileBase upload)
        {
            try
            {
                var user = _userManager.GetById(model.Id);

                string pathPic = user.photo;

                if (upload != null && upload.ContentLength > 0)
                {
                    var pic = new AddPhotos();
                    pathPic = pic.AddImage(upload, Server.MapPath("/images/Account/"), "/images/Account/");
                }

                user       = Mapper.Map <EditProfileViewModel, User>(model, user);
                user.photo = pathPic;
                _userManager.Update(user);

                return(RedirectToRoute("UserPage"));
            }
            catch (Exception)
            {
                return(View());
            }
        }
Ejemplo n.º 2
0
        public ActionResult AddService(AddServiceViewModel model, HttpPostedFileBase upload)
        {
            try
            {
                var pic     = new AddPhotos();
                var pathPic = pic.AddImage(upload, Server.MapPath("/images/Services/"), "/images/Services/");
                var entity  = Mapper.Map <AddServiceViewModel, Services>(model);
                entity.servicePhoto = new List <ServicePhoto>()
                {
                    new ServicePhoto
                    {
                        photo = new Photo
                        {
                            name = pathPic,
                            date = DateTime.Now
                        }
                    }
                };
                _servicesManager.Add(entity);

                return(RedirectToRoute("UserPage"));
            }
            catch (Exception)
            {
                return(View());
            }
        }
Ejemplo n.º 3
0
        public ActionResult SaveUploadedFile()
        {
            bool   isSavedSuccessfully = true;
            string fName = "";

            AddUser userModel = new AddUser();

            userModel.Name  = Request.Form["name"].Split(',')[0];
            userModel.Email = Request.Form["email"].Split(',')[0];

            //Insert new user, if user with same name + email already exists then return their id.
            int userId = new ImageUserService().AddUser(userModel);


            for (int i = 0; i < Request.Files.Count; i++)
            {
                //For each image uploaded, insert into db with connected userId
                HttpPostedFileBase file = Request.Files[i];
                fName = file.FileName;

                if (file != null && file.ContentLength > 0)
                {
                    AddPhotos imagesModel = new AddPhotos();

                    MemoryStream target = new MemoryStream();
                    file.InputStream.CopyTo(target);
                    byte[] data = target.ToArray();
                    imagesModel.Image       = data;
                    imagesModel.Name        = fName;
                    imagesModel.Description = Request.Form["description"].Split(',')[i];
                    imagesModel.UserId      = userId;

                    imageUserService.AddImages(imagesModel);
                }
            }

            if (isSavedSuccessfully)
            {
                return(Json(new { Message = fName }));
            }
            else
            {
                return(Json(new { Message = "Error in saving file" }));
            }
        }
Ejemplo n.º 4
0
 public void AddImages(AddPhotos model)
 {
     using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString))
     {
         conn.Open();
         {
             using (SqlCommand cmd = new SqlCommand("dbo.Images_Add", conn))
             {
                 cmd.CommandType = System.Data.CommandType.StoredProcedure;
                 cmd.Parameters.Add("@Image", SqlDbType.VarBinary).Value = model.Image;
                 cmd.Parameters.AddWithValue("@Name", model.Name);
                 cmd.Parameters.AddWithValue("@Description", model.Description);
                 cmd.Parameters.AddWithValue("@UserId", model.UserId);
                 cmd.ExecuteNonQuery();
             }
         }
         conn.Close();
     }
 }
Ejemplo n.º 5
0
 public ActionResult AddPhotoService(ServicePageViewModel model, HttpPostedFileBase upload)
 {
     try
     {
         var pic     = new AddPhotos();
         var pathPic = pic.AddImage(upload, Server.MapPath("/images/Services/"), "/images/Services/");
         var entity  = new ServicePhoto()
         {
             id_service = model.Id,
             photo      = new Photo()
             {
                 name = pathPic,
                 date = DateTime.Now,
             }
         };
         _servicePhotoManager.Add(entity);
         return(RedirectToRoute("ServicePage", new { id = model.Id }));
     }
     catch (Exception)
     {
         return(RedirectToRoute("ServicePage", new { id = model.Id }));
     }
 }