Exemplo n.º 1
0
        public async Task <IDataResult <EssayCollection> > AddEssay(EssayModel essay)
        {
            try
            {
                EssayCollection essayCollection = new EssayCollection();
                essayCollection.Title      = essay.Title;
                essayCollection.Author     = essay.Author;
                essayCollection.Language   = essay.Language;
                essayCollection.Subject    = essay.Subject;
                essayCollection.Record     = DateTime.Now;
                essayCollection.LastUpdate = DateTime.Now;
                if (essay.Comment == null)
                {
                    essayCollection.Comment = "*No Comment*";
                }
                else
                {
                    essayCollection.Comment = essay.Comment;
                }

                var fileName      = Path.GetFileName(essay.TextFile.FileName);
                var fileExtension = Path.GetExtension(fileName);
                var path          = String.Concat(Convert.ToString(Guid.NewGuid()), fileExtension);
                essayCollection.Path = "/" + path;

                if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                }
                using (var localFile = File.OpenWrite(fileName))

                    using (var uploadedFile = essay.TextFile.OpenReadStream())
                    {
                        uploadedFile.CopyTo(localFile);
                        await uploadedFile.FlushAsync();
                    }
                //var objfiles = new Files()
                //{
                //    DocumentId = 0,
                //    Name = newFileName,
                //    FileType = fileExtension,
                //    CreatedOn = DateTime.Now
                //};

                //using (var target = new MemoryStream())
                //{
                //    files.CopyTo(target);
                //    objfiles.DataFiles = target.ToArray();
                //}
                await _essayMongoService.Insert(essayCollection);

                return(new SuccessDataResult <EssayCollection>("Completed!"));
            }
            catch (Exception ex)
            {
                return(new FailDataResult <EssayCollection>("Oops! Something is wrong..." + ex.Message.ToString()));
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> UpdateEssay(string essayId, EssayModel model)
        {
            var result = await _essayService.UpdateEssay(essayId, model);

            if (result.Success)
            {
                return(new ObjectResult(result.Message));
            }
            else
            {
                return(BadRequest(result.Message));
            }
        }
Exemplo n.º 3
0
        public async Task <IActionResult> AddEssay([FromForm] EssayModel essay)
        {
            var result = await _essayService.AddEssay(essay);

            if (result.Success)
            {
                return(new ObjectResult(result.Message));
            }
            else
            {
                return(BadRequest(result.Message));
            }
        }
Exemplo n.º 4
0
        public bool UpdateEssayToDb(EssayModel model, int id, string useremail)
        {
            var result = false;

            try
            {
                var context = new ManageDataContext();
                context.Connection.Open();
                var tblIcerik  = context.tbl_PortalHaber_Iceriks.FirstOrDefault(u => u.HaberId == id);
                var tblIcerik2 = context.tbl_PortalHaber_Icerik2s.FirstOrDefault(u => u.HaberId == id);
                var user       = context.tbl_PortalHaber_Yazars.FirstOrDefault(u => u.EPosta == useremail);

                if (tblIcerik != null)
                {
                    tblIcerik.Banner_Tip    = model.BannerId;
                    tblIcerik.HaberUrl      = model.Baslik.Replace('Ç', 'c').Replace('ç', 'c').Replace(' ', '-').Replace('Ö', 'o').Replace('ö', 'o').Replace('ğ', 'g').Replace('Ğ', 'g').Replace('ü', 'u').Replace('Ü', 'u').Replace('İ', 'i').Replace('Ş', 's').Replace('ş', 's').Replace('ı', 'i').Replace('.', '-').Replace('&', '-').Replace('/', '-');
                    tblIcerik.Haber_Resim   = model.HaberResimFile.FileName;
                    tblIcerik.KategoriId    = model.KategoriId;
                    tblIcerik.KaynakId      = model.KaynakId;
                    tblIcerik.Onay_Tarih    = DateTime.Now;
                    tblIcerik.Site_Id       = model.SiteId;
                    tblIcerik.HaberAciklama = model.Aciklama;
                    tblIcerik.HaberBaslik   = model.Baslik;

                    if (tblIcerik2 != null)
                    {
                        tblIcerik2.Etiketler  = model.Hastags;
                        tblIcerik2.HaberMetni = model.EssayContent;
                        if (user != null)
                        {
                            tblIcerik2.YazarId = user.YazarId;
                        }
                    }


                    context.SubmitChanges();
                    result = true;

                    context.Connection.Close();
                    context.Dispose();
                }
            }
            catch (Exception)
            {
                result = false;
                throw;
            }

            return(result);
        }
Exemplo n.º 5
0
        public EssayModel FillREssayModelFordUpdate(EssayModel essayModel, int id)
        {
            var context = new ManageDataContext();

            context.Connection.Open();
            //var icerik = context.tbl_PortalHaber_Iceriks.FirstOrDefault(u => u.HaberId == id);


            var icerikall = (from icerik in context.tbl_PortalHaber_Iceriks
                             join icerik2 in context.tbl_PortalHaber_Icerik2s
                             on icerik.HaberId equals icerik2.HaberId
                             select new
            {
                icerik.HaberId,
                icerik.HaberBaslik,
                icerik.HaberAciklama,
                icerik.KategoriId,
                icerik.HaberUrl,
                icerik.KaynakId,
                icerik.Site_Id,
                icerik.Onay_Tarih,
                icerik.Haber_Resim,
                icerik.Onay,
                icerik.Banner_Tip,
                icerik2.HaberMetni,
                icerik2.Etiketler,
                icerik2.YazarId,
            }).FirstOrDefault(u => u.HaberId == id);

            context.Connection.Close();


            context.Connection.Close();
            if (icerikall != null)
            {
                essayModel.Baslik             = icerikall.HaberBaslik;
                essayModel.Aciklama           = icerikall.HaberAciklama;
                essayModel.EssayContent       = icerikall.HaberMetni;
                essayModel.HaberUrl           = icerikall.HaberUrl;
                essayModel.Hastags            = icerikall.Etiketler;
                essayModel.KategoriId         = (int)icerikall.KategoriId;
                essayModel.KaynakId           = (int)icerikall.KaynakId;
                essayModel.SiteId             = (int)icerikall.Site_Id;
                essayModel.HaberResimFileText = "~/Img/" + icerikall.Haber_Resim;
            }


            return(essayModel);
        }
Exemplo n.º 6
0
        public bool InsertEssayToDb(EssayModel model)
        {
            var icerik = new tbl_PortalHaber_Icerik();

            icerik.HaberBaslik   = model.Baslik;
            icerik.HaberAciklama = model.Aciklama;
            icerik.KategoriId    = model.KategoriId;
            icerik.HaberUrl      = model.Baslik.Replace('Ç', 'c').Replace('ç', 'c').Replace(' ', '-').Replace('Ö', 'o').Replace('ö', 'o').Replace('ğ', 'g').Replace('Ğ', 'g').Replace('ü', 'u').Replace('Ü', 'u').Replace('İ', 'i').Replace('Ş', 's').Replace('ş', 's').Replace('ı', 'i').Replace('.', '-').Replace('&', '-').Replace('/', '-');
            icerik.KaynakId      = model.KaynakId;
            icerik.Site_Id       = model.SiteId;
            icerik.Onay_Tarih    = DateTime.Now;
            icerik.Haber_Resim   = model.HaberResimFile.FileName;
            icerik.Onay          = false;
            icerik.HaberId       = model.BannerId;

            //var context = new ManageDataContext();
            //context.Connection.Open();
            context.tbl_PortalHaber_Icerik.Add(icerik);
            context.SaveChanges();
            //context.SubmitChanges();

            var tblPortalHaberIcerik = context.tbl_PortalHaber_Icerik.OrderByDescending(p => p.HaberId).FirstOrDefault();

            if (tblPortalHaberIcerik != null)
            {
                var haberId = tblPortalHaberIcerik.HaberId;
                var icerik2 = new tbl_PortalHaber_Icerik2();
                icerik2.Etiketler  = model.Hastags;
                icerik2.HaberMetni = model.EssayContent;
                icerik2.HaberId    = haberId;

                var yazar = context.tbl_PortalHaber_Yazar.FirstOrDefault(u => u.EPosta == model.UserEmail);
                icerik2.YazarId = yazar.YazarId;

                context.tbl_PortalHaber_Icerik2.Add(icerik2);
                context.SaveChanges();
                //context.SubmitChanges();
            }

            //context.Connection.Close();
            //context.Connection.Dispose();

            return(true);
        }
Exemplo n.º 7
0
        public ActionResult UpdateEssay(int id)
        {
            var useremail = Session["useremail"];

            if (useremail != null)
            {
                // ComboBox'ların doldurulması sağlanır.
                EssayModel.ActionType = "update";
                EssayModel.UpdateId   = id;

                EssayModel.DropDownListKategori = _dbOperation.GetKategoriList();
                EssayModel.DropDownListKaynak   = _dbOperation.GetKaynakList();
                EssayModel.DropDownListSite     = _dbOperation.GetSiteList();
                EssayModel.DropDownListBanner   = _dbOperation.GetBannerList();
                EssayModel = _dbOperation.FillREssayModelFordUpdate(EssayModel, id);

                return(View("UpdateEssay", EssayModel));
            }
            else
            {
                return(View("Login"));
            }
        }
Exemplo n.º 8
0
        public async Task <IDataResult <EssayCollection> > UpdateEssay(string essayId, EssayModel model)
        {
            try
            {
                var _filter = Builders <EssayCollection> .Filter.Where(x => x.Id == essayId);

                var _get = await _essayMongoService.GetBy(_filter);

                _get.Title      = model.Title;
                _get.Subject    = model.Subject;
                _get.Language   = model.Language;
                _get.Comment    = model.Comment;
                _get.Author     = model.Author;
                _get.LastUpdate = DateTime.UtcNow + TimeSpan.FromHours(3);
                await _essayMongoService.Replace(_get);

                return(new SuccessDataResult <EssayCollection>("Completed!"));
            }
            catch (Exception ex)
            {
                return(new FailDataResult <EssayCollection>("Oops! Record couldn't find..." + ex.Message.ToString()));
            }
        }
Exemplo n.º 9
0
        public ActionResult AddEditorContent(EssayModel model)
        {
            var view = "";

            EssayModel.DropDownListKategori = _dbOperation.GetKategoriList();
            EssayModel.DropDownListKaynak   = _dbOperation.GetKaynakList();
            EssayModel.DropDownListSite     = _dbOperation.GetSiteList();
            EssayModel.DropDownListBanner   = _dbOperation.GetBannerList();

            if (ModelState.IsValid)
            {
                model.UserEmail = Session["useremail"].ToString();
                // Insert Image to Img Folder
                var    fileName = Path.GetFileName(model.HaberResimFile.FileName);
                var    ext      = Path.GetExtension(model.HaberResimFile.FileName);
                string name     = Path.GetFileNameWithoutExtension(fileName);
                var    guid     = Guid.NewGuid().ToString();
                string newsfile = name + "_" + guid + ext;
                var    path     = Path.Combine(Server.MapPath("~/Img"), newsfile);
                model.HaberResimFile.SaveAs(path);
            }
            else
            {
                if (EssayModel.ActionType == "create")
                {
                    ViewBag.Error = "Resim Seçiniz";
                    view          = "AddEssay";
                }
                else if (EssayModel.ActionType == "update")
                {
                    ViewBag.Error = "Resim Seçiniz";
                    view          = "UpdateEssay";
                }
                return(View(view, EssayModel));
            }

            var result = false;

            // Insert To Icerik ve Icerik2
            if (EssayModel.ActionType == "create")
            {
                result = _dbOperation.InsertEssayToDb(model);
            }
            else
            {
                var useremail = Session["useremail"].ToString();
                var id        = EssayModel.UpdateId;
                result = _dbOperation.UpdateEssayToDb(model, id, useremail);
            }



            if (result && EssayModel.ActionType == "create")
            {
                view = "AddEssay";
            }
            else if (result && EssayModel.ActionType == "update")
            {
                view = "UpdateEssay";
            }
            return(View(view, EssayModel));
        }