Exemplo n.º 1
0
 public JsonResult EditComment(vmComment input)
 {
     if (!ModelState.IsValid)
     {
         return(Json("faild"));
     }
     try
     {
         using (var _Context = new ApplicationDbContext())
         {
             var _objEntityComment = new RepositoryPattern <PostComment>(_Context);
             var CurrentItem       = _objEntityComment.GetByPredicate(x => x.ID == input.ID);
             if (CurrentItem != null)
             {
                 CurrentItem.Is_Active = input.Is_Active;
                 CurrentItem.FullName  = input.FullName;
                 CurrentItem.Comment   = input.Comment;
                 _objEntityComment.Update(CurrentItem);
                 _objEntityComment.Save();
                 _objEntityComment.Dispose();
             }
         }
     }
     catch (Exception)
     {
         return(Json("OK"));
     }
     return(Json("OK"));
 }
 public TableConfigListsServiceModel GetDatabaseConnectionName()
 {
     try
     {
         List <IdNameServiceModel> dataBaseLists = new List <IdNameServiceModel>();
         using (var dataBaseConnectionRepo = new RepositoryPattern <DatabaseConnection>())
         {
             dataBaseLists = dataBaseConnectionRepo.SelectAll().Select(a => new IdNameServiceModel {
                 Name = a.Name, Id = a.Id
             }).ToList();
         }
         List <TableConfiguration> tableConfigLists = new List <TableConfiguration>();
         using (var repo = new RepositoryPattern <TableConfiguration>())
         {
             tableConfigLists = repo.SelectAll().ToList();
         }
         return(new TableConfigListsServiceModel()
         {
             IdAndName = dataBaseLists,
             TableConfigList = Mapper.Map <List <TableConfiguratonServiceModel> >(tableConfigLists)
         });
     }
     catch (Exception ex)
     {
         throw;
     }
 }
Exemplo n.º 3
0
        public Task SendMail(string subject, string message)
        {
            using (var _Context = new ApplicationDbContext())
            {
                var objEntityEmailInfo = new RepositoryPattern <EmailInfo>(_Context);
                var Info = objEntityEmailInfo.SearchFor(x => x.IsActive == "1").ToList().FirstOrDefault();

                SmtpClient  smtpClient  = new SmtpClient(Info.SMTP);
                MailMessage mailMessage = new MailMessage();


                smtpClient.Host = Info.HostName;
                mailMessage.To.Add(new MailAddress(Info.ToEmail));
                mailMessage.Subject              = subject;
                mailMessage.SubjectEncoding      = Encoding.UTF8;
                mailMessage.IsBodyHtml           = true;
                mailMessage.From                 = new MailAddress(Info.FromEmail, subject);
                mailMessage.BodyEncoding         = Encoding.UTF8;
                mailMessage.Body                 = message;
                smtpClient.UseDefaultCredentials = false;
                NetworkCredential networkCredential = (NetworkCredential)(smtpClient.Credentials = new NetworkCredential(Info.FromEmail, Info.Pass));
                smtpClient.Credentials = networkCredential;

                return(smtpClient.SendMailAsync(mailMessage));
            }
        }
Exemplo n.º 4
0
 public ActionResult AllPost()
 {
     using (var _context = new ApplicationDbContext())
     {
         var _objEntityPost = new RepositoryPattern <Post>(_context);
         return(View(_objEntityPost.GetAll()));
     }
 }
Exemplo n.º 5
0
 // GET: ControlPanel/Blog
 public ActionResult CreatePost()
 {
     using (var _Context = new ApplicationDbContext())
     {
         var objEntityCategory = new RepositoryPattern <Category>(_Context);
         ViewBag.ListCategory = objEntityCategory.SearchFor(x => x.IsActive == "1").ToList();
         return(View());
     }
 }
Exemplo n.º 6
0
 public ActionResult CommnetDetails()
 {
     using (var _Context = new ApplicationDbContext())
     {
         var objPostCommnet = new RepositoryPattern <PostComment>(_Context);
         var AllCommnet     = objPostCommnet.GetAll().OrderByDescending(x => x.SendTime).OrderByDescending(x => x.SendDate).OrderBy(x => x.Is_Read);
         return(View(AllCommnet));
     }
 }
Exemplo n.º 7
0
        public ActionResult WebSiteVisit()
        {
            using (var _Conetxt = new ApplicationDbContext())
            {
                var objectVisitWebSite = new RepositoryPattern <WebsiteVisit>(_Conetxt);
                var allVisit           = objectVisitWebSite.GetAll();

                return(View(allVisit));
            }
        }
Exemplo n.º 8
0
 public JsonResult GetCommentsDetails(int id)
 {
     using (var _Context = new ApplicationDbContext())
     {
         var _objEntityComment = new RepositoryPattern <PostComment>(_Context);
         var result            = _objEntityComment.GetByPredicate(x => x.ID == id);
         // _objEntityMedia.Dispose();
         return(Json(Data.UnProxy(_Context, result)));
     }
 }
Exemplo n.º 9
0
        public DataSet GetDataBrowserDetails(DatabrowserDropdownFilterServiceModel fieldDetailsFilterModel)
        {
            try
            {
                if (fieldDetailsFilterModel == null)
                {
                    // return exceptions
                }
                //get connection related Details
                int connectionId      = fieldDetailsFilterModel.ConnectionId;
                var connectionDetails = new DatabaseConnection();
                var paginations       = fieldDetailsFilterModel.PageSize * (fieldDetailsFilterModel.PageNumber - 1);

                using (var repo = new RepositoryPattern <DatabaseConnection>())
                {
                    connectionDetails = repo.SelectByID(connectionId);
                }
                List <FieldConfiguration> fieldConfigurationDetails = new List <FieldConfiguration>();
                using (var repo = new RepositoryPattern <FieldConfiguration>())
                {
                    fieldConfigurationDetails = repo.SelectAll().Where(a => a.TableConfigId == fieldDetailsFilterModel.Id && a.IsDisplay.HasValue && a.IsDisplay.Value).ToList();
                }
                string refTableSelectQuery = string.Empty;
                string masterTableAlias    = $"{fieldDetailsFilterModel.MasterTableName}_{DateTime.UtcNow.ToFileTimeUtc()}";

                ///////
                var leftJoinDetails = GetLeftJoinTablesDetailsToDisplay(fieldConfigurationDetails, fieldDetailsFilterModel, masterTableAlias, out refTableSelectQuery);
                //////

                string selectQuery = GetSelectQueryDetails(fieldDetailsFilterModel.MasterTableName, fieldConfigurationDetails, refTableSelectQuery, masterTableAlias);
                string totalCount  = "SELECT COUNT(*) AS [TotalCount] FROM " + fieldDetailsFilterModel.MasterTableName;

                string query = selectQuery + " " + leftJoinDetails + " ORDER BY " + masterTableAlias + ".Id OFFSET " + paginations + " ROWS FETCH NEXT " + fieldDetailsFilterModel.PageSize + " ROWS ONLY  " + totalCount;

                string connectionString = "server= " + connectionDetails.ServerInstanceName + ";Initial Catalog=" + connectionDetails.DatabaseName + " ;uid=" + connectionDetails.UserName + ";pwd=" + connectionDetails.Password + ";";

                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    conn.Open();
                    using (SqlCommand cmd = new SqlCommand(query, conn))
                    {
                        DataSet        ds = new DataSet();
                        SqlDataAdapter da = new SqlDataAdapter();
                        da = new SqlDataAdapter(cmd);
                        da.Fill(ds);
                        conn.Close();
                        return(ds);
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Exemplo n.º 10
0
        public void NonExistingEnvironmentVariablesStopsResolution()
        {
            var pattern = new RepositoryPattern("$ENV1, $ENV2 and $ENV3");
            var context = new Mock <IPatternResolutionContext>();

            context.Setup(c => c.GetEnvironmentVariable("ENV1")).Returns("e1");

            var resolution = pattern.Resolve(context.Object);

            resolution.Should().BeNull();
        }
        public List <string> GetTablesFromDatabase(TableConfigurationDatabaseFilterServiceModel dataToFilter)
        {
            try
            {
                if (dataToFilter.ConnectionId == default(int))
                {
                    return(null);
                }
                //get Database Name from database connection
                DatabaseConnection dataBaseDetails;
                List <string>      tableNames = new List <string>();
                using (var dataBaseConnectionRepo = new RepositoryPattern <DatabaseConnection>())
                {
                    dataBaseDetails = dataBaseConnectionRepo.SelectByID(dataToFilter.ConnectionId);
                }
                if (dataBaseDetails == null)
                {
                    return(null);
                }

                var connectionString = "server= " + dataBaseDetails.ServerInstanceName + ";Initial Catalog=" + dataBaseDetails.DatabaseName + " ;uid=" + dataBaseDetails.UserName + ";pwd=" + dataBaseDetails.Password + ";";
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    conn.Open();
                    string query = string.Empty;
                    if (dataToFilter.IsTable)
                    {
                        query = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE';";
                    }
                    else
                    {
                        query = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS";
                    }

                    using (SqlCommand cmd = new SqlCommand(query, conn))
                    {
                        using (IDataReader dr = cmd.ExecuteReader())
                        {
                            while (dr.Read())
                            {
                                tableNames.Add(dr[0].ToString());
                            }
                        }
                    }
                }


                return(tableNames);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Exemplo n.º 12
0
 public void SaveLog()
 {
     if (C_LikeViewList.CompareListCreateTimeWithTimeNow())
     {
         var LstLikeView = C_LikeViewList.GetAllLikeView();
         if (LstLikeView.Count()
             != 0)
         {
             using (var _Context = new ApplicationDbContext())
             {
                 var _objEntityActivity = new RepositoryPattern <Activity>(_Context);
                 foreach (var item in LstLikeView)
                 {
                     if (item.ActionTypeID == Convert.ToInt32(EnumMethod.ActionType.View) || item.ActionTypeID == Convert.ToInt32(EnumMethod.ActionType.Like) || item.ActionTypeID == Convert.ToInt32(EnumMethod.ActionType.Downlaod))
                     {
                         var NewItem = new Activity
                         {
                             ActionTime     = item.ActionTime,
                             DateMiladi     = item.DateMiladi,
                             DateShamsi     = item.DateShamsi,
                             ActivityTypeId = item.ActionTypeID,
                             PostId         = item.PostID,
                             Browser        = item.Browser,
                             Device         = item.Device,
                             IP_Address     = item.IP_Address,
                             HostName       = item.HostName,
                             MoreInfo       = ""
                         };
                         _objEntityActivity.Insert(NewItem);
                     }
                     else if (item.ActionTypeID == Convert.ToInt32(EnumMethod.ActionType.DisLike))
                     {
                         var CurrItemDele = _objEntityActivity.GetByPredicate(x =>
                                                                              x.PostId == item.PostID &&
                                                                              x.Browser == item.Browser &&
                                                                              x.Device == item.Device &&
                                                                              x.HostName == item.HostName &&
                                                                              x.IP_Address == item.IP_Address &&
                                                                              x.ActivityTypeId == Convert.ToInt32(EnumMethod.ActionType.Like));
                         if (CurrItemDele != null)
                         {
                             _objEntityActivity.Delete(CurrItemDele.ID);
                         }
                     }
                 }
                 _objEntityActivity.Save();
                 _objEntityActivity.Dispose();
                 C_LikeViewList.ClearLikeViewList();
             }
         }
     }
 }
Exemplo n.º 13
0
        public void ResolutionFailsIfNoVersionInfo()
        {
            var pattern = new RepositoryPattern("/root/%NAME/%FILENAME.%VERSION.%EXT");
            var context = new Mock <IPatternResolutionContext>();

            context.SetupGet(c => c.DependencyName).Returns("dependency");
            context.SetupGet(c => c.FileName).Returns("something");
            context.SetupGet(c => c.Extension).Returns("dll");
            context.SetupGet(c => c.Version).Returns((string)null);

            var resolution = pattern.Resolve(context.Object);

            resolution.Should().BeNull();
        }
Exemplo n.º 14
0
        public void EnvironmentVariableSupport()
        {
            var pattern = new RepositoryPattern("$ENV1, $ENV2 and $ENV3");
            var context = new Mock <IPatternResolutionContext>();

            context.Setup(c => c.GetEnvironmentVariable("ENV1")).Returns("e1");
            context.Setup(c => c.GetEnvironmentVariable("ENV2")).Returns("e2");
            context.Setup(c => c.GetEnvironmentVariable("ENV3")).Returns("e3");

            var resolution = pattern.Resolve(context.Object);

            resolution.Should().NotBeNull();
            resolution.Should().Be("e1, e2 and e3");
        }
        public List <string> GetPrimaryKeyTableColumns(IdNameServiceModel columnFilter)
        {
            try
            {
                if (columnFilter == null)
                {
                    //return exception
                }
                if (columnFilter.Id == default(int))
                {
                    //return exception
                }
                DatabaseConnection dataBaseDetails;
                List <string>      columnName = new List <string>();
                List <TableDetailsServiceModel> tableDetails = new List <TableDetailsServiceModel>();
                using (var dataBaseConnectionRepo = new RepositoryPattern <DatabaseConnection>())
                {
                    dataBaseDetails = dataBaseConnectionRepo.SelectByID(columnFilter.Id);
                }
                if (dataBaseDetails == null)
                {
                    //return null;
                }
                var connectionString = "server= " + dataBaseDetails.ServerInstanceName + ";Initial Catalog=" + dataBaseDetails.DatabaseName + " ;uid=" + dataBaseDetails.UserName + ";pwd=" + dataBaseDetails.Password + ";";
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    conn.Open();
                    string query = string.Empty;
                    query = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '" + columnFilter.Name + "' ORDER BY ORDINAL_POSITION ";
                    using (SqlCommand cmd = new SqlCommand(query, conn))
                    {
                        using (IDataReader dr = cmd.ExecuteReader())
                        {
                            while (dr.Read())
                            {
                                columnName.Add(dr[0].ToString());
                            }
                        }
                    }
                    conn.Close();
                }

                return(columnName);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Exemplo n.º 16
0
        public void WhenVersionNotNeededItWorks()
        {
            var pattern = new RepositoryPattern("/root/%NAME/%FILENAME.%EXT");
            var context = new Mock <IPatternResolutionContext>();

            context.SetupGet(c => c.DependencyName).Returns("dependency");
            context.SetupGet(c => c.FileName).Returns("something");
            context.SetupGet(c => c.Extension).Returns("dll");
            context.SetupGet(c => c.Version).Returns((string)null);

            var resolution = pattern.Resolve(context.Object);

            resolution.Should().NotBeNull();
            resolution.Should().Be("/root/dependency/something.dll");
        }
Exemplo n.º 17
0
        public void ReferenceVariablesReplaced()
        {
            var pattern = new RepositoryPattern("/root/%NAME/%FILENAME.%VERSION.%EXT");
            var context = new Mock <IPatternResolutionContext>();

            context.SetupGet(c => c.DependencyName).Returns("dependency");
            context.SetupGet(c => c.FileName).Returns("something");
            context.SetupGet(c => c.Extension).Returns("dll");
            context.SetupGet(c => c.Version).Returns("version");

            var resolution = pattern.Resolve(context.Object);

            resolution.Should().NotBeNull();
            resolution.Should().Be("/root/dependency/something.version.dll");
        }
Exemplo n.º 18
0
        public ActionResult EditPost(int id)
        {
            DatabaseOperation _dop = new DatabaseOperation();

            using (var _Context = new ApplicationDbContext())
            {
                var objEntityCategory = new RepositoryPattern <Category>(_Context);
                ViewBag.ListCategory = objEntityCategory.SearchFor(x => x.IsActive == "1").ToList();

                var Result = new List <vm_AllPost>();
                Result = _dop.GetAllPost("all").Where(x => x.PostID == id).ToList();

                return(View(Result.FirstOrDefault()));
            }
        }
        private void DeleteColumnsIfNeeded(List <FieldConfigurationServiceModel> deleteData)
        {
            var idsToDelete = deleteData.Select(v => v.Id).ToList();

            using (var repo = new RepositoryPattern <FieldConfiguration>())
            {
                var dataToDelete = repo.SelectAll().Where(v => idsToDelete.Contains(v.Id)).ToList();
                repo.BulkDelete(dataToDelete);
            }
            using (var repo = new RepositoryPattern <FieldMappingConfiguration>())
            {
                var dataToDelete = repo.SelectAll().Where(v => idsToDelete.Contains(v.FieldConfigurationId ?? 0)).ToList();
                repo.BulkDelete(dataToDelete);
            }
        }
Exemplo n.º 20
0
 public ProcessResult <List <DataBaseConnectionServiceModel> > GetAll()
 {
     try
     {
         List <DataBaseConnectionServiceModel> dataBaseConnection = null;
         using (var repo = new RepositoryPattern <DatabaseConnection>())
         {
             var result = repo.SelectAll().ToList();
             dataBaseConnection = Mapper.Map <List <DataBaseConnectionServiceModel> >(result);
         }
         return(dataBaseConnection.GetResult());
     }
     catch (Exception ex)
     {
         throw;
     }
 }
Exemplo n.º 21
0
        /// <summary>
        /// بررسی کاربر که اینکه مدیای جاری رو قبلا لایک کرده یا نه
        /// </summary>
        /// <returns></returns>
        ///
        public bool CheckLastActionPost(int PostID, int ActivityType)
        {
            string CurrIP = objNetworkOperation.ClientIPaddress();
            string CurrHN = objNetworkOperation.ClientHostName();
            string CurrDT = objNetworkOperation.ClientDeviceType();
            string CurrBr = objNetworkOperation.ClientBrowser();

            using (var _Context = new ApplicationDbContext())
            {
                var _objEntityAction = new RepositoryPattern <Activity>(_Context);
                var PostLikeState    = _objEntityAction.SearchFor(x =>
                                                                  x.Posts.ID == PostID &&
                                                                  x.IP_Address == CurrIP &&
                                                                  x.HostName == CurrHN &&
                                                                  x.Device == CurrDT &&
                                                                  x.Browser == CurrBr &&
                                                                  x.ActivityType.ID == ActivityType)
                                       .ToList()
                                       .LastOrDefault();

                if (PostLikeState != null)
                {
                    return(true);
                }
            }
            //Search In RAM List
            var _LikeView = C_LikeViewList.GetAllLikeView();

            if (!(_LikeView == null || _LikeView.Count() == 0))
            {
                PostAction CurrItem = _LikeView.FirstOrDefault(x =>
                                                               x.PostID == PostID &&
                                                               x.Browser == CurrBr &&
                                                               x.Device == CurrDT &&
                                                               x.HostName == CurrHN &&
                                                               x.IP_Address == CurrIP &&
                                                               x.ActionTypeID == ActivityType);
                if (CurrItem != null)
                {
                    //در صورتي كه توي ليست (رم) باشد
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 22
0
        public async Task <ActionResult> Contact_US(string Name, string Phone, string Email, string Message, string CaptchaText)
        {
            if (CaptchaText.ToLower() == HttpContext.Session["captchastring"].ToString().ToLower())
            {
                Session.Remove("captchastring");
                var _objEntityMessage = new RepositoryPattern <Comment>(new ApplicationDbContext());
                var NewItem           = new Comment
                {
                    FullName    = Name,
                    PhoneNumber = Phone,
                    Email       = Email,
                    CommentUser = Message,
                    SendDate    = DateConvertor.DateToNumber(DateConvertor.TodayDate()),
                    SendTime    = DateConvertor.TimeNow(),
                    Is_Read     = "0"
                };
                _objEntityMessage.Insert(NewItem);
                _objEntityMessage.Save();
                _objEntityMessage.Dispose();

                try
                {
                    OpratingClasses.EmailService emailService = new OpratingClasses.EmailService();
                    var strSubject = " نام و نام خانوادگی : " + NewItem.FullName;
                    var strMessage =
                        " ارتباط با مديريت وب سايت" +
                        "  <br />  " + NewItem.CommentUser +
                        "  <br />  " + " ایمیل : " + NewItem.Email +
                        "  <br />  " + " شماره همراه : " + NewItem.PhoneNumber +
                        "  <br />  " + " تاریخ و ساعت ارسال : " + NewItem.SendDate + " - " + NewItem.SendTime;

                    await emailService.SendMail(strSubject, strMessage);
                }
                catch (Exception)
                {
                }

                return(Json("OK"));
            }
            else
            {
                return(Json("CaptchaTextMistake"));
                //ViewBag.Message = "CAPTCHA verification failed!";
            }
        }
Exemplo n.º 23
0
 public List <DatabrowserDropdownFilterServiceModel> GetTableConfigurationDetails()
 {
     try
     {
         var details = new List <DatabrowserDropdownFilterServiceModel>();
         using (var repo = new RepositoryPattern <TableConfiguration>())
         {
             details = repo.SelectAll().Select(a => new DatabrowserDropdownFilterServiceModel
             {
                 ConnectionId = a.ConnectionId ?? 0, Id = a.Id, MasterTableName = a.MasterTableName, Name = a.Name
             }).ToList();
         }
         return(details);
     }
     catch (Exception ex)
     {
         throw;
     }
 }
Exemplo n.º 24
0
 public string CreateDataBaseConnection(DataBaseConnectionServiceModel dataBaseConnection)
 {
     try
     {
         if (dataBaseConnection == null)
         {
         }
         using (var dataBaseRepo = new RepositoryPattern <DatabaseConnection>())
         {
             var data = Mapper.Map <DatabaseConnection>(dataBaseConnection);
             dataBaseRepo.Insert(data);
             dataBaseRepo.Save();
         }
         return("");
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
Exemplo n.º 25
0
 public string DeleteDatabaseConnection(int id)
 {
     try
     {
         if (id == default(int))
         {
             // retirn exception
         }
         using (var dataBaseRepo = new RepositoryPattern <DatabaseConnection>())
         {
             dataBaseRepo.Delete(id);
             dataBaseRepo.Save();
         }
         return("Database Connection Deleted successfully");
     }
     catch (Exception ex)
     {
         throw;
     }
 }
Exemplo n.º 26
0
        public ActionResult ContentDetail(int PostID)
        {
            try
            {
                ViewBag.BeforeLiked = _dop.CheckLastActionPost(PostID, Convert.ToInt32(EnumMethod.ActionType.Like));
            }
            catch (Exception)
            {
                ViewBag.BeforeLiked = false;
            }
            ViewAndLikeLog(PostID, Convert.ToInt32(EnumMethod.ActionType.View));
            var Result = new List <vm_AllPost>();

            Result = _dop.GetAllPost("all").Where(x => x.PostID == PostID && x.IsActive == "1").ToList();
            using (var _Context = new ApplicationDbContext())
            {
                var _objEntityPostComment = new RepositoryPattern <PostComment>(_Context);
                var _PostComment          = _objEntityPostComment.SearchFor(x => x.PostID == PostID && x.Is_Active == "1").ToList();
                ViewBag.listPostComment = _PostComment;
            }

            ViewBag.SeoData = HtmlPageSEO.GetHeadPageData(Result.FirstOrDefault().Title, new robot[] { robot.index, robot.follow },
                                                          new HtmlMetaTag[]
            {
                new HtmlMetaTag()
                {
                    name = MetaName.author, content = "محمد بن سعيد"
                },
                new HtmlMetaTag()
                {
                    name = MetaName.keywords, content = Result.FirstOrDefault().Labels
                },
                new HtmlMetaTag()
                {
                    name = MetaName.description, content = Result.FirstOrDefault().SeoMetaDescription
                }
            },
                                                          null);

            return(View(Result));
        }
Exemplo n.º 27
0
 /// <summary>
 /// پاک کردن تصویر یک پست - وبلاگ
 /// </summary>
 /// <param name="PostID"></param>
 /// <returns></returns>
 public bool DeleteImageOfPost(string MediaID)
 {
     if (MediaID == null || MediaID == "")
     {
         return(false);
     }
     using (var _Context = new ApplicationDbContext())
     {
         var _objEntityImage = new RepositoryPattern <Image>(_Context);
         var itemMedia       = _objEntityImage.GetByPredicate(x => x.ID == MediaID);
         if (HelpOperation.RemoveMediaFromServer(itemMedia.FilePathOnServer))
         {
             _objEntityImage.Delete(itemMedia.ID);
             _objEntityImage.Save();
             _objEntityImage.Dispose();
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Exemplo n.º 28
0
 public JsonResult ReadComment(int id)
 {
     try
     {
         using (var _Context = new ApplicationDbContext())
         {
             var _objEntityComment = new RepositoryPattern <PostComment>(_Context);
             var CurrentItem       = _objEntityComment.GetByPredicate(x => x.ID == id);
             if (CurrentItem != null)
             {
                 CurrentItem.Is_Read = "1";
                 _objEntityComment.Update(CurrentItem);
                 _objEntityComment.Save();
                 _objEntityComment.Dispose();
             }
         }
     }
     catch (Exception)
     {
         return(Json("OK"));
     }
     return(Json("OK"));
 }
Exemplo n.º 29
0
        //public ContentResult UploadFile(HttpPostedFileBase hpf,List<vm_FileUploadInfo> vm_Info)
        public JsonResult PublishPost(vmPublishPost input) //string Title, int CategoryID, string Content, string IsActive, bool FlagHaveFile,string Tagsinput)
        {                                                  //, string Labels
            try
            {
                string NewImageID;
                //InfoUser AppUser = new InfoUser();
                var TodayDateShamsi = DateConvertor.DateToNumber(DateConvertor.TodayDate());
                //var NewNewsCode = HelpOperation.NewsCode(Convert.ToInt32(TodayDateShamsi));
                if (input.FlagHaveFile == true)
                {
                    HelpOperation.CreateArchiveFolderOnTheServer();
                    HttpPostedFileBase hpf = Request.Files[0] as HttpPostedFileBase;
                    var FileSize           = HelpOperation.ToFileSize(hpf.ContentLength);
                    var GuidID             = HelpOperation.NewGuidID();
                    var FileNameOnServer   = GuidID + Path.GetExtension(hpf.FileName);
                    var FilePath           = @"~\MediaFiles\Image\" + FileNameOnServer;
                    var FilePathOnServer   = Server.MapPath(FilePath);
                    var FileUrl            = HelpOperation.MapToUrl(FilePath);
                    Request.Files[0].SaveAs(FilePathOnServer);
                    using (var _ContextImage = new ApplicationDbContext())
                    {
                        var _objEntityImage = new RepositoryPattern <Image>(_ContextImage);
                        var NewItemImage    = new Image
                        {
                            ID               = GuidID,
                            TitleUrl         = input.Title,
                            FileName         = FileNameOnServer,
                            FileSize         = FileSize,
                            FileUrl          = FileUrl,
                            FilePathOnServer = FilePath
                        };
                        NewImageID = GuidID;
                        _objEntityImage.Insert(NewItemImage);
                        _objEntityImage.Save();
                        _objEntityImage.Dispose();
                    }

                    using (var _ContextPost = new ApplicationDbContext())
                    {
                        var objEntityPost = new RepositoryPattern <Post>(_ContextPost);
                        var newItemPost   = new Post
                        {
                            Title      = input.Title.Trim(),
                            ImageID    = NewImageID,
                            CategoryID = input.CategoryID,
                            //Categories = new List<Category>() {  new Category() {ID = CategoryID, } },
                            Content            = input.Content,
                            IsActive           = input.IsActive == "true" ? "0" : "1",
                            Labels             = input.Tagsinput.Trim(),
                            SeoMetaDescription = input.SeoMetaDescription.Trim(),
                            PostDate           = DateConvertor.DateToNumber(DateConvertor.TodayDate()),
                            PostTime           = DateConvertor.TimeNowShort()
                        };
                        objEntityPost.Insert(newItemPost);
                        objEntityPost.Save();

                        objEntityPost.Dispose();
                    }
                }
                return(Json("OK"));
            }
            catch (Exception)
            {
                return(Json("Faild"));
            }
        }
Exemplo n.º 30
0
        public JsonResult EditPost(vmPublishPost input)
        {
            try
            {
                //delete image of Post To Insert New Image For Post (Update)
                if (input.FlagHaveFile == true)
                {
                    DatabaseOperation objDatabaseOperation = new DatabaseOperation();
                    using (var _Context1 = new ApplicationDbContext())
                    {
                        var objEntityPost = new RepositoryPattern <Post>(_Context1);
                        var CurrentItem   = objEntityPost.GetByPredicate(x => x.ID == input.PostID);
                        if (objDatabaseOperation.DeleteImageOfPost(CurrentItem.ImageID))
                        {
                            //InfoUser AppUser = new InfoUser();
                            var TodayDateShamsi = DateConvertor.DateToNumber(DateConvertor.TodayDate());
                            //var NewNewsCode = HelpOperation.NewsCode(Convert.ToInt32(TodayDateShamsi));
                            HelpOperation.CreateArchiveFolderOnTheServer();
                            HttpPostedFileBase hpf = Request.Files[0] as HttpPostedFileBase;
                            var FileSize           = HelpOperation.ToFileSize(hpf.ContentLength);
                            var GuidID             = CurrentItem.ImageID;
                            var FileNameOnServer   = GuidID + Path.GetExtension(hpf.FileName);
                            var FilePath           = @"~\MediaFiles\Image\" + FileNameOnServer;
                            var FilePathOnServer   = Server.MapPath(FilePath);
                            var FileUrl            = HelpOperation.MapToUrl(FilePath);
                            Request.Files[0].SaveAs(FilePathOnServer);
                            using (var _ContextImage = new ApplicationDbContext())
                            {
                                var _objEntityImage = new RepositoryPattern <Image>(_ContextImage);
                                var NewItemImage    = new Image
                                {
                                    ID               = GuidID,
                                    TitleUrl         = input.Title,
                                    FileName         = FileNameOnServer,
                                    FileSize         = FileSize,
                                    FileUrl          = FileUrl,
                                    FilePathOnServer = FilePath
                                };
                                _objEntityImage.Insert(NewItemImage);
                                _objEntityImage.Save();
                                _objEntityImage.Dispose();
                            }
                        }
                    }
                }

                using (var _context = new ApplicationDbContext())
                {
                    var objEntityPost = new RepositoryPattern <Post>(_context);
                    var CurrentItem   = objEntityPost.GetByPredicate(x => x.ID == input.PostID);

                    CurrentItem.Title      = input.Title.Trim();
                    CurrentItem.CategoryID = input.CategoryID;
                    //Categories = new List<Category>() {  new Category() {ID = CategoryID, } },
                    CurrentItem.Content            = input.Content;
                    CurrentItem.IsActive           = input.IsActive == "true" ? "0" : "1";
                    CurrentItem.Labels             = input.Tagsinput.Trim();
                    CurrentItem.SeoMetaDescription = input.SeoMetaDescription.Trim();
                    //CurrentItem.PostDate = DateConvertor.DateToNumber(DateConvertor.TodayDate());
                    //CurrentItem.PostTime = DateConvertor.TimeNowShort();

                    objEntityPost.Update(CurrentItem);
                    objEntityPost.Save();

                    objEntityPost.Dispose();
                }
                return(Json("OK"));
            }
            catch (Exception)
            {
                return(Json("Faild"));
            }
        }