Esempio n. 1
0
        public IHttpActionResult MyPublishUpdate([FromBody] PUBLICATION publish, int id)
        {
            using (MynoteDBEntities db = new MynoteDBEntities())
            {
                try
                {
                    var result = db.PUBLICATIONS.FirstOrDefault(x => x.Id == id);
                    if (result == null)
                    {
                        return(BadRequest());
                    }

                    result.PubContent      = publish.PubContent;
                    result.PubTitle        = publish.PubTitle;
                    result.PubModifiedDate = DateTime.Now;
                    result.PubSefLink      = publish.PubSefLink;
                    int save = db.SaveChanges();
                    if (save != 0)
                    {
                        return(Ok());
                    }
                    else
                    {
                        return(BadRequest());
                    }
                }
                catch (Exception e)
                {
                    return(BadRequest(e.Message));
                }
            }
        }
Esempio n. 2
0
        public IHttpActionResult AddMyPublish([FromBody] PUBLICATION publish)
        {
            int id = UserInf.GetUser();

            using (MynoteDBEntities db = new MynoteDBEntities())
            {
                try
                {
                    publish.PubUserId = id;
                    db.PUBLICATIONS.Add(publish);
                    int save = db.SaveChanges();
                    if (save != 0)
                    {
                        return(Ok());
                    }
                    else
                    {
                        return(BadRequest());
                    }
                }
                catch (Exception e)
                {
                    return(BadRequest(e.Message));
                }
            }
        }
Esempio n. 3
0
        public ActionResult SupprimerPublication(int?id)
        {
            PUBLICATION pub = null;

            try
            {
                if (id == null)
                {
                    throw new ArgumentNullException("id");
                }

                pub = db.GetPublication(id).First();
            }
            catch
            {
                TempData[Constantes.CLE_MSG_RETOUR] = new Message(Message.TYPE_MESSAGE.ERREUR, Resources.Publication.idPublicationInvalide);
            }

            if (pub != null)
            {
                return(View(pub));
            }

            return(RedirectToAction("Publications", "Sectoriel"));
        }
Esempio n. 4
0
        public ActionResult DeleteConfirmed(int id)
        {
            PUBLICATION pUBLICATION = db.PUBLICATIONs.Find(id);

            db.PUBLICATIONs.Remove(pUBLICATION);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 5
0
        // POST api/values
        public HttpResponseMessage Post(TravelEditModel model)
        {
            if (HttpContext.Current.Request.Headers["Authorization"] == null)
            {
                throw new HttpResponseException(HttpStatusCode.Unauthorized);
            }
            else
            {
                try
                {
                    TRAVEL travelBdd = new TRAVEL();
                    travelBdd.ID_ARRIVALAGENCY   = model.ArrivalAgency.Id;
                    travelBdd.ID_DEPARTUREAGENCY = model.DepartureAgency.Id;
                    travelBdd.ARRIVALHOUR        = model.ArrivalTime;
                    travelBdd.DEPARTUREHOUR      = model.DepartureTime;
                    travelBdd.CAPACITY           = model.Capacity;

                    PUBLICATION publicationBdd = new PUBLICATION();

                    string      tokenString = HttpContext.Current.Request.Headers["Authorization"];
                    UserManager userManager = new UserManager();
                    publicationBdd.ID_USER            = userManager.getUserFromSession(new Guid(tokenString));
                    publicationBdd.TITLE              = model.Publication.Title;
                    publicationBdd.DESCRIPTION        = model.Publication.Description;
                    publicationBdd.ID_GROUP           = 1;
                    publicationBdd.ID_CATEGORY        = 1;
                    publicationBdd.DATE_TIME_CREATION = DateTime.Now.AddHours(1);


                    manager.add(travelBdd, publicationBdd);
                    return(new HttpResponseMessage()
                    {
                        Content = new JsonContent(new
                        {
                            Success = true,     //error
                            Message = "Success" //return exception
                        })
                    });
                }
                catch (Exception e)
                {
                    return(new HttpResponseMessage()
                    {
                        Content = new JsonContent(new
                        {
                            Success = false,                                                                                                      //error
                            Message = "Exception with token :" + HttpContext.Current.Request.Headers["Authorization"] + " Error :" + e.ToString() //return exception
                        })
                    });
                }
            }
        }
Esempio n. 6
0
 public ActionResult Edit([Bind(Include = "ID_PUBLICATION,ID_USER,TITLE,DESCRIPTION,ID_CATEGORY,ID_GROUP")] PUBLICATION pUBLICATION)
 {
     if (ModelState.IsValid)
     {
         db.Entry(pUBLICATION).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ID_CATEGORY = new SelectList(db.CATEGORies, "ID_CATEGORY", "TITLE", pUBLICATION.ID_CATEGORY);
     ViewBag.ID_GROUP    = new SelectList(db.GROUPs, "ID_GROUP", "LABEL", pUBLICATION.ID_GROUP);
     ViewBag.ID_USER     = new SelectList(db.USERs, "ID_USER", "FIRST_NAME", pUBLICATION.ID_USER);
     return(View(pUBLICATION));
 }
Esempio n. 7
0
        // GET: Publication/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PUBLICATION pUBLICATION = db.PUBLICATIONs.Find(id);

            if (pUBLICATION == null)
            {
                return(HttpNotFound());
            }
            return(View(pUBLICATION));
        }
Esempio n. 8
0
        public void remove(PUBLICATION publication)
        {
            try
            {
                var Context = new connext_dbEntities();
                Context.PUBLICATIONs.Remove(publication);
                Context.SaveChanges();
            }
            catch (Exception ex)
            {
#if DEBUG
                throw new Exception("Impossible de supprimer le lieu." + Environment.NewLine + ex.StackTrace);
#else
                throw new Exception("Impossible de supprimer le lieu.");
#endif
            }
        }
Esempio n. 9
0
        // GET: Publication/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PUBLICATION pUBLICATION = db.PUBLICATIONs.Find(id);

            if (pUBLICATION == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ID_CATEGORY = new SelectList(db.CATEGORies, "ID_CATEGORY", "TITLE", pUBLICATION.ID_CATEGORY);
            ViewBag.ID_GROUP    = new SelectList(db.GROUPs, "ID_GROUP", "LABEL", pUBLICATION.ID_GROUP);
            ViewBag.ID_USER     = new SelectList(db.USERs, "ID_USER", "FIRST_NAME", pUBLICATION.ID_USER);
            return(View(pUBLICATION));
        }
Esempio n. 10
0
        public void add(TRAVEL travel, PUBLICATION publication)
        {
            try
            {
                var Context = new connext_dbEntities();
                publication.TRAVELs.Add(travel);
                Context.PUBLICATIONs.Add(publication);
                Context.SaveChanges();
            }
            catch (Exception ex)
            {
#if DEBUG
                throw new Exception("Impossible de modifier le covoiturage." + Environment.NewLine + ex.StackTrace);
#else
                throw new Exception("Impossible de modifier le covoiturage.");
#endif
            }
        }
Esempio n. 11
0
        public ActionResult ObtenirPublication(int?id)
        {
            PUBLICATION pub = null;

            try
            {
                if (id == null)
                {
                    throw new ArgumentNullException("id");
                }

                pub = db.GetPublication(id).First();
            }
            catch
            {
                TempData[Constantes.CLE_MSG_RETOUR] = new Message(Message.TYPE_MESSAGE.ERREUR, Resources.Publication.idPublicationInvalide);
            }

            if (pub != null)
            {
                if (User.IsInRole("admin") || ((List <SECTEUR>)Session["lstSect"]).Any(s => s.ID == pub.IDSECTEUR))
                {
                    var cd = new ContentDisposition {
                        FileName = pub.NOMFICHIERORIGINAL, Inline = false
                    };
                    Response.AppendHeader("Content-Disposition", cd.ToString());

                    try
                    {
                        return(File(IOFile.ReadAllBytes(Fichiers.CheminEnvois(pub.NOMFICHIERSERVEUR)), pub.NOMFICHIERORIGINAL));
                    }
                    catch (IOException)
                    {
                        TempData[Constantes.CLE_MSG_RETOUR] = new Message(Message.TYPE_MESSAGE.ERREUR, Resources.Publication.publicationErreurFichier);
                    }
                }
                else
                {
                    TempData[Constantes.CLE_MSG_RETOUR] = new Message(Message.TYPE_MESSAGE.ERREUR, Resources.Publication.accesRefuse);
                }
            }

            return(RedirectToAction("Publications", "Sectoriel"));
        }
Esempio n. 12
0
        public ActionResult AjoutPublication(PUBLICATION envoiPubli)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    HttpPostedFileBase fichier = envoiPubli.fichier;

                    string mimetype    = fichier.ContentType;
                    string nomOriginal = Fichiers.GetNomOriginal(fichier.FileName);
                    string nomServeur  = Fichiers.GetNomServeur(fichier.FileName);

                    fichier.SaveAs(Fichiers.CheminEnvois(nomServeur));

                    ObjectParameter idNouvPub = new ObjectParameter("idpub", typeof(int));
                    db.AjouterPublication(envoiPubli.TITRE, envoiPubli.DESCRIPTION, envoiPubli.IDSECTEUR, envoiPubli.IDSUJET, nomOriginal, nomServeur, mimetype, WebSecurity.CurrentUserId, idNouvPub);

                    List <String> motsCles = envoiPubli.TITRE.Split(new Char[] { ' ' }).ToList();

                    if (!String.IsNullOrEmpty(envoiPubli.motcles))
                    {
                        motsCles.AddRange(envoiPubli.motcles.Split(new Char[] { ' ' }));
                    }

                    db.UpdateMotsClesPub((int)idNouvPub.Value, MotsCles.TraiterMotsCles(motsCles));

                    TempData[Constantes.CLE_MSG_RETOUR] = new Message(Message.TYPE_MESSAGE.SUCCES, Resources.Publication.publicationAjoutee);

                    return(RedirectToAction("Publications", "Sectoriel"));
                }
                catch (Exception ex)
                {
                    TempData[Constantes.CLE_MSG_RETOUR] = new Message(Message.TYPE_MESSAGE.ERREUR, Resources.Publication.publicationErreur + " (" + ex.GetType() + ")");
                }
            }

            List <GetSecteurs_Result>          listeSecteurs  = db.GetSecteursLocalises(Session);
            List <GetSujetsPublication_Result> listeSujetsPub = db.GetSujetsPublicationLocalises(Session).ToList();

            ViewData[Constantes.CLE_SECTEURS]          = listeSecteurs;
            ViewData[Constantes.CLE_SUJETSPUBLICATION] = listeSujetsPub;

            return(View(envoiPubli));
        }
Esempio n. 13
0
        public ActionResult SupprimerPublication(int?id, string confirmer, string annuler)
        {
            if (!String.IsNullOrEmpty(confirmer) && String.IsNullOrEmpty(annuler))
            {
                PUBLICATION pub = null;

                try
                {
                    if (id == null)
                    {
                        throw new ArgumentNullException("id");
                    }

                    pub = db.GetPublication(id).First();
                }
                catch
                {
                    TempData[Constantes.CLE_MSG_RETOUR] = new Message(Message.TYPE_MESSAGE.ERREUR, Resources.Publication.idPublicationInvalide);
                }

                if (pub != null)
                {
                    db.SupprimerPublication(id);

                    string cheminEnvoi = Fichiers.CheminEnvois(pub.NOMFICHIERSERVEUR);

                    if (IOFile.Exists(cheminEnvoi))
                    {
                        IOFile.Delete(cheminEnvoi);
                    }

                    TempData[Constantes.CLE_MSG_RETOUR] = new Message(Message.TYPE_MESSAGE.SUCCES, Resources.Publication.publicationSupprimee);
                }
            }

            return(RedirectToAction("Publications", "Sectoriel"));
        }