Пример #1
0
        public int Save(CLayer.AccommodationFiles file)
        {
            List <DataPlug.Parameter> param = new List <DataPlug.Parameter>();

            param.Add(Connection.GetParameter("pFileId", DataPlug.DataType._BigInt, file.FileId));
            param.Add(Connection.GetParameter("pAccommodationId", DataPlug.DataType._BigInt, file.AccommodationId));
            param.Add(Connection.GetParameter("pFileName", DataPlug.DataType._Varchar, file.FileName));
            object result = Connection.ExecuteQueryScalar("accommodationfiles_Save", param);

            return(Connection.ToInteger(result));
        }
Пример #2
0
        public CLayer.AccommodationFiles Get(long fileId)
        {
            CLayer.AccommodationFiles result = null;
            List <DataPlug.Parameter> param  = new List <DataPlug.Parameter>();

            param.Add(Connection.GetParameter("pFileId", DataPlug.DataType._BigInt, fileId));
            DataTable dt = Connection.GetTable("accommodationfiles_Get", param);

            if (dt.Rows.Count > 0)
            {
                result = new CLayer.AccommodationFiles()
                {
                    FileId          = Connection.ToLong(dt.Rows[0]["FileId"]),
                    AccommodationId = Connection.ToLong(dt.Rows[0]["AccommodationId"]),
                    FileName        = Connection.ToString(dt.Rows[0]["FileName"])
                };
            }
            return(result);
        }
 public ActionResult AccommodationPictureDelete(long id)
 {
     try
     {
         CLayer.AccommodationFiles pf = BLayer.AccommodationFiles.Get(id);
         BLayer.AccommodationFiles.Delete(id);
         if (System.IO.File.Exists(Server.MapPath("~/Files/Property/Accommodation/" + pf.AccommodationId.ToString() + "/" + pf.FileName)))
         {
             System.IO.File.Delete(Server.MapPath("~/Files/Property/Accommodation/" + pf.AccommodationId.ToString() + "/" + pf.FileName));
         }
         CLayer.Accommodation ac       = BLayer.Accommodation.Get(pf.AccommodationId);
         Models.PropertyModel property = GetDetails(ac.PropertyId);
         property.ActiveTab = "accommodation";
         property.Accommodations.Accommodation           = AccommodationGet(pf.AccommodationId);
         property.Accommodations.Accommodation.ActiveTab = "pictures";
         return(View("Index", property));
         //return RedirectToAction("Index", new { id = ac.PropertyId });
     }
     catch (Exception ex)
     {
         Common.LogHandler.HandleError(ex);
         return(Redirect("~/ErrorPage"));
     }
 }
        public ActionResult AccommodationPictureSave(Models.AccommodationPicturesModel data)
        {
            try
            {
                if (data.AccommodationId == 0)
                {
                    Models.PropertyModel property = GetDetails(data.PropertyId);
                    property.ActiveTab = "accommodation";
                    property.Accommodations.Accommodation           = AccommodationGet(data.AccommodationId);
                    property.Accommodations.Accommodation.ActiveTab = "pictures";
                    return(View("Index", property));
                }

                if (ModelState.IsValid)
                {
                    #region Save
                    string FileNamePart = data.AccommodationId.ToString() + DateTime.Now.ToString("ddMMyyyyHHmmss");
                    CLayer.AccommodationFiles acmdtn = new CLayer.AccommodationFiles()
                    {
                        AccommodationId = data.AccommodationId,
                        FileId          = data.FileId,
                        FileName        = FileNamePart + System.IO.Path.GetFileNameWithoutExtension(data.AccommodationPhoto.FileName) + ".jpg"
                    };

                    if (data.AccommodationPhoto != null && data.AccommodationPhoto.ContentLength > 0)
                    {
                        int      Sizevalue             = Convert.ToInt32(ConfigurationManager.AppSettings.Get("FileUploadSizeInMB"));
                        int      MaxContentLength      = 1024 * 1024 * Sizevalue; //3 MB
                        string[] AllowedFileExtensions = new string[] { ".jpg", ".gif", ".png", ".jpeg" };

                        if (!AllowedFileExtensions.Contains(data.AccommodationPhoto.FileName.Substring(data.AccommodationPhoto.FileName.LastIndexOf('.'))))
                        {
                            ModelState.AddModelError(string.Empty, "Please use files of type: " + string.Join(", ", AllowedFileExtensions));
                        }
                        else if (data.AccommodationPhoto.ContentLength > MaxContentLength)
                        {
                            ModelState.AddModelError(string.Empty, "Your file is too large, maximum allowed size is: " + MaxContentLength + " MB");
                        }
                        else
                        {
                            var fileName = FileNamePart + System.IO.Path.GetFileName(data.AccommodationPhoto.FileName); //uploaded file from UI

                            if (!System.IO.Directory.Exists(Server.MapPath("~/Files/Temp/")))
                            {
                                System.IO.Directory.CreateDirectory(Server.MapPath("~/Files/Temp/"));
                            }
                            var path = System.IO.Path.Combine(Server.MapPath("~/Files/Temp/"), fileName);
                            data.AccommodationPhoto.SaveAs(path);


                            int   maxHeight = Convert.ToInt32(ConfigurationManager.AppSettings.Get("MaxImgHeight"));
                            Image tempimage = Image.FromFile(path);

                            Image resized = Common.Utils.ScaleImage(tempimage, maxHeight);

                            //var fileName = acmdtn.FileName;
                            if (!System.IO.Directory.Exists(Server.MapPath("~/Files/Property/Accommodation/" + data.AccommodationId.ToString() + "/")))
                            {
                                System.IO.Directory.CreateDirectory(Server.MapPath("~/Files/Property/Accommodation/" + data.AccommodationId.ToString() + "/"));
                            }
                            var path2 = System.IO.Path.Combine(Server.MapPath("~/Files/Property/Accommodation/" + data.AccommodationId.ToString() + "/"), acmdtn.FileName);
                            resized.Save(path2, System.Drawing.Imaging.ImageFormat.Jpeg);
                            try
                            {
                                resized.Dispose();
                                tempimage.Dispose();
                                if (System.IO.File.Exists(path))
                                {
                                    System.IO.File.Delete(path);
                                }
                            }
                            catch
                            {
                            }
                            BLayer.AccommodationFiles.Save(acmdtn);
                            ModelState.Clear();
                        }
                    }
                    #endregion
                    Models.PropertyModel property = GetDetails(data.PropertyId);
                    property.ActiveTab = "accommodation";
                    property.Accommodations.Accommodation           = AccommodationGet(data.AccommodationId);
                    property.Accommodations.Accommodation.ActiveTab = "pictures";
                    return(View("Index", property));
                    //return RedirectToAction("Index", new { id = data.PropertyId });
                }
                return(Redirect("~/ErrorPage"));
            }
            catch (Exception ex)
            {
                Common.LogHandler.HandleError(ex);
                return(Redirect("~/ErrorPage"));
            }
        }
Пример #5
0
 public static int Save(CLayer.AccommodationFiles file)
 {
     DataLayer.AccommodationFiles ac = new DataLayer.AccommodationFiles();
     file.Validate();
     return(ac.Save(file));
 }