// ////////////////////////////////////////////////////////////////////////////////////////////////////////
        // To Create a new Appreciation
        // POST: api/appreciations/Create
        // ////////////////////////////////////////////////////////////////////////////////////////////////////////

        // ________________________________________________________
        // Display the "Create" View of CategoriesController
        // ________________________________________________________



        public async Task <IActionResult> Create(Appreciation appreciation)
        {
            List <LineItem> lineItems;
            List <Order>    orders;

            string uriGetLineItems = _url + "GetLineItems";
            string uriGetOrders    = _url + "GetOrders";


            HttpResponseMessage responseLineItem = await _client.GetAsync(uriGetLineItems); // HTTP GET

            HttpResponseMessage responseorders = await _client.GetAsync(uriGetOrders);

            if (responseLineItem.IsSuccessStatusCode)
            {
                lineItems = await responseLineItem.Content.ReadAsAsync <List <LineItem> >();

                ViewData["IdLineItem"] = new SelectList(lineItems, "Id", "Id", appreciation.IdLineItem);// Add To ViewData
            }

            if (responseorders.IsSuccessStatusCode)
            {
                orders = await responseorders.Content.ReadAsAsync <List <Order> >();

                ViewData["IdOrder"] = new SelectList(orders, "Id", "ShippingAddress", appreciation.IdOrder);// Add To ViewData
            }


            ViewData["IdAppreciation"] = appreciation.Id;

            return(View("Create"));
        }
Example #2
0
        public async Task <IActionResult> PutAppreciation([FromRoute] int id, [FromBody] Appreciation appreciation)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != appreciation.Id)
            {
                return(BadRequest());
            }

            _context.Entry(appreciation).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AppreciationExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #3
0
        public async Task <IHttpActionResult> PutAppreciation(int id, Appreciation appreciation)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != appreciation.AppreciationId)
            {
                return(BadRequest());
            }

            db.Entry(appreciation).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AppreciationExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Example #4
0
 public string GetEndingMessage(Theme theme, Appreciation appreciation, Alignment alignment)
 {
     if ((int)theme < themes.Count && (int)appreciation < themes[(int)theme].appreciations.Count && (int)alignment < themes[(int)theme].appreciations[(int)appreciation].alignments.Count)
     {
         return(themes[(int)theme].appreciations[(int)appreciation].alignments[(int)alignment].endingMessage);
     }
     return("");
 }
        public ActionResult DeleteConfirmed(string id)
        {
            Appreciation appreciation = db.Appreciations.Find(id);

            db.Appreciations.Remove(appreciation);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        // TDDO TODO TODO TODO  TDDO TODO TODO TODO  TDDO TODO TODO TODO  TDDO TODO TODO TODO  TDDO TODO TODO TODO  TDDO TODO TODO TODO
        // TDDO TODO TODO TODO  TDDO TODO TODO TODO  TDDO TODO TODO TODO  TDDO TODO TODO TODO  TDDO TODO TODO TODO  TDDO TODO TODO TODO

        // ________________________________________________________
        // Post (Send) the new Ressource Appreciation to the API Server
        // ________________________________________________________
        public async Task <IActionResult> PostAppreciation(Appreciation appreciation)
        {
            ViewData["IdAppreciation"] = appreciation.Id;

            HttpResponseMessage response = await _client.PostAsJsonAsync("api/appreciations", appreciation); // HTTP POST

            response.EnsureSuccessStatusCode();
            return(RedirectToAction("Index", "Appreciations"));
        }
        public async Task <IActionResult> PutAppreciations(int id, Appreciation appreciation)
        {
            // NLog
            string message = $"(API Server) -Try to PUT (update) Appreciation " + id + "(Id) - Controller : AppreciationsController; " +
                             "Actionname: Put(...); HTTP method : HttpPut; Time: " + DateTime.Now + "\n";

            _logger.Info(message);

            try
            {
                _context.Entry(appreciation).State = EntityState.Modified;
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                // NLog Framework Call

                // LOG INFO
                _logger.Info("INFORMATION DETAILS, Exception occured during operation : " + message);
                _logger.Info("EXCEPTION DETAILS: " + ex.Message + "\n");

                // LOG WARN
                _logger.Warn("WARNING DETAILS, Exception occured during operation : " + message);
                _logger.Warn("EXCEPTION DETAILS: " + ex.Message + "\n");


                // LOG ERROR
                _logger.Error("ERROR DETAILS, Exception occured during operation : " + message);
                _logger.Error("EXCEPTION DETAILS: " + ex.Message + "\n");


                // LOG TRACE
                _logger.Trace("WARNING DETAILS, Exception occured during operation : " + message);
                _logger.Trace("EXCEPTION DETAILS: " + ex.Message + "\n");


                // LOG FATAL
                _logger.Fatal("FATAL DETAILS, Exception occured during operation : " + message);
                _logger.Fatal("EXCEPTION DETAILS: " + ex.Message + "\n");


                // LOG DEGUG
                _logger.Debug("DEGUG DETAILS, Exception occured during operation : " + message);
                _logger.Debug("EXCEPTION DETAILS: " + ex.Message + "\n");

                if (id != appreciation.Id)
                {
                    return(BadRequest());
                }
                else
                {
                    return(NotFound());
                }
            }

            return(NoContent());
        }
        public async Task <ActionResult <Appreciation> > ReadRessource(int?id) // int ? - supprimé
        {
            // NLog
            string message = $"(API Server) -Try to GET Appreciation " + id + "(Id) - Controller name: AppreciationsController; " +
                             "Actionname: ReadRessource(...); HTTP method : HttpGet; Time: " + DateTime.Now + "\n";

            _logger.Info(message);


            Appreciation appreciation = new Appreciation();

            try
            {
                appreciation = await _context.Appreciations
                               .Include(a => a.IdLineItemNavigation)
                               .Include(a => a.IdOrderNavigation)
                               .Include(a => a.IdPaymentNavigation)
                               .FirstOrDefaultAsync(m => m.Id == id);
            }
            catch (Exception ex)
            {
                // NLog Framework Call

                // LOG INFO
                _logger.Info("INFORMATION DETAILS, Exception occured during operation : " + message);
                _logger.Info("EXCEPTION DETAILS: " + ex.Message + "\n");

                // LOG WARN
                _logger.Warn("WARNING DETAILS, Exception occured during operation : " + message);
                _logger.Warn("EXCEPTION DETAILS: " + ex.Message + "\n");


                // LOG ERROR
                _logger.Error("ERROR DETAILS, Exception occured during operation : " + message);
                _logger.Error("EXCEPTION DETAILS: " + ex.Message + "\n");


                // LOG TRACE
                _logger.Trace("WARNING DETAILS, Exception occured during operation : " + message);
                _logger.Trace("EXCEPTION DETAILS: " + ex.Message + "\n");


                // LOG FATAL
                _logger.Fatal("FATAL DETAILS, Exception occured during operation : " + message);
                _logger.Fatal("EXCEPTION DETAILS: " + ex.Message + "\n");


                // LOG DEGUG
                _logger.Debug("DEGUG DETAILS, Exception occured during operation : " + message);
                _logger.Debug("EXCEPTION DETAILS: " + ex.Message + "\n");

                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }

            return(appreciation);
        }
 public ActionResult Edit([Bind(Include = "Id,Commentaire,Ponctualite,Securite,Fiabilite,Confort,Courtoisie")] Appreciation appreciation)
 {
     if (ModelState.IsValid)
     {
         db.Entry(appreciation).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(appreciation));
 }
        public ActionResult Create([Bind(Include = "Id,Commentaire,Ponctualite,Securite,Fiabilite,Confort,Courtoisie")] Appreciation appreciation)
        {
            if (ModelState.IsValid)
            {
                db.Appreciations.Add(appreciation);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(appreciation));
        }
        public async Task <ActionResult <Category> > PostAppreciations(Appreciation appreciation)
        {
            // NLog
            string message = $"Log Information(API Server) -Try to POST Appreciation " + appreciation.Id + "(Id) - Controller : AppreciationsController; " +
                             "Actionname: Post(...); HTTP method : HttpPost; Time: " + DateTime.Now + "\n";

            _logger.Info(message);

            try
            {
                _context.Appreciations.Add(appreciation);
                await _context.SaveChangesAsync();

                _context.Entry(appreciation).GetDatabaseValues();
                return(CreatedAtAction("GetAppreciations", new { id = appreciation.Id }, appreciation));
            }
            catch (Exception ex)
            {
                // NLog Framework Call

                // LOG INFO
                _logger.Info("INFORMATION DETAILS, Exception occured during operation : " + message);
                _logger.Info("EXCEPTION DETAILS: " + ex.Message + "\n");

                // LOG WARN
                _logger.Warn("WARNING DETAILS, Exception occured during operation : " + message);
                _logger.Warn("EXCEPTION DETAILS: " + ex.Message + "\n");

                // LOG ERROR
                _logger.Error("ERROR DETAILS, Exception occured during operation : " + message);
                _logger.Error("EXCEPTION DETAILS: " + ex.Message + "\n");

                // LOG TRACE
                _logger.Trace("WARNING DETAILS, Exception occured during operation : " + message);
                _logger.Trace("EXCEPTION DETAILS: " + ex.Message + "\n");

                // LOG FATAL
                _logger.Fatal("FATAL DETAILS, Exception occured during operation : " + message);
                _logger.Fatal("EXCEPTION DETAILS: " + ex.Message + "\n");

                // LOG DEGUG
                _logger.Debug("DEGUG DETAILS, Exception occured during operation : " + message);
                _logger.Debug("EXCEPTION DETAILS: " + ex.Message + "\n");

                if (AppreciationExists(appreciation.Id))
                {
                    return(Conflict());
                }
                else
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
                }
            }
        }
        // ________________________________________________________
        // UPDATE : Update an Appreciation ->  <form asp-action="PutAppreciation">
        // PUT: / api/appreciations/
        // ________________________________________________________
        // Update a Appreciation ->  <form asp-action="PutAppreciation">
        public async Task <IActionResult> PutAppreciation(int id, Appreciation appreciation)
        {
            ViewData["IdAppreciation"] = appreciation.Id;

            string uri = _url + id;
            HttpResponseMessage response = await _client.PutAsJsonAsync(uri, appreciation); // HTTP PUT

            response.EnsureSuccessStatusCode();

            return(RedirectToAction("Index", "Appreciations"));
        }
Example #13
0
        public async Task <IHttpActionResult> GetAppreciation(int id)
        {
            Appreciation appreciation = await db.Appreciations.FindAsync(id);

            if (appreciation == null)
            {
                return(NotFound());
            }

            return(Ok(appreciation));
        }
Example #14
0
        public async Task <IHttpActionResult> PostAppreciation(Appreciation appreciation)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Appreciations.Add(appreciation);
            await db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = appreciation.AppreciationId }, appreciation));
        }
Example #15
0
        public async Task <IActionResult> PostAppreciation([FromBody] Appreciation appreciation)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.Appreciation.Add(appreciation);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetAppreciation", new { id = appreciation.Id }, appreciation));
        }
        // ////////////////////////////////////////////////////////////////////////////////////////////////////////
        // READ: Return a Appreciation
        // GET: .../ api/Appreciations/
        // ////////////////////////////////////////////////////////////////////////////////////////////////////////

        public async Task <Appreciation> GetAppreciationSync()
        {
            Appreciation        appreciation = null;
            HttpResponseMessage response     = await _client.GetAsync(_url); // HTTP GET

            if (response.IsSuccessStatusCode)
            {
                appreciation = await response.Content.ReadAsAsync <Appreciation>();
            }

            ViewData["IdAppreciation"] = appreciation.Id;
            return(appreciation);
        }
        // GET: Appreciations/Delete/5
        public ActionResult Delete(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Appreciation appreciation = db.Appreciations.Find(id);

            if (appreciation == null)
            {
                return(HttpNotFound());
            }
            return(View(appreciation));
        }
Example #18
0
        public async Task <IHttpActionResult> DeleteAppreciation(int id)
        {
            Appreciation appreciation = await db.Appreciations.FindAsync(id);

            if (appreciation == null)
            {
                return(NotFound());
            }

            db.Appreciations.Remove(appreciation);
            await db.SaveChangesAsync();

            return(Ok(appreciation));
        }
        public IActionResult Post([FromBody] Appreciation model)
        {
            var appreciation = _context.Appreciations.FirstOrDefault(a => a.ApplicationUserID == model.ApplicationUserID && a.DestinationID == model.DestinationID);

            if (appreciation != null)
            {
                appreciation.Content    = model.Content;
                appreciation.CreateDate = model.CreateDate;
                appreciation.Rating     = model.Rating;

                _context.Appreciations.Update(appreciation);
                _context.SaveChanges();
                return(CreatedAtRoute("GetAppreciation", new { userID = appreciation.ApplicationUserID, destinationID = appreciation.DestinationID }, appreciation));
            }
            _context.Appreciations.Add(model);
            _context.SaveChanges();
            return(CreatedAtRoute("GetAppreciation", new { userID = model.ApplicationUserID, destinationID = model.DestinationID }, model));
        }
        public IActionResult Put(AppreciationKeyFromModel key, [FromBody] Appreciation model)
        {
            if (key.ApplicationUserID != model.ApplicationUserID || key.DestinationID != model.DestinationID)
            {
                return(BadRequest());
            }
            var appreciation = _context.Appreciations.FirstOrDefault(a => a.ApplicationUserID == model.ApplicationUserID && a.DestinationID == model.DestinationID);

            if (appreciation == null)
            {
                return(NotFound());
            }
            appreciation.Content    = model.Content;
            appreciation.Rating     = model.Rating;
            appreciation.CreateDate = model.CreateDate;
            _context.Appreciations.Update(appreciation);
            _context.SaveChanges();
            return(NoContent());
        }
Example #21
0
        public ActionResult Index(string name, string gender, int[] articleId)
        {
            if ((name != null) && (gender != null) && (articleId != null))
            {
                var form = new Form();
                form.Name   = name;
                form.Gender = gender;
                Article article;
                if (ModelState.IsValid)
                {
                    db.Forms.Create(form);
                    db.Save();
                    int          formId = db.Forms.GetAll().ToList().Last().FormID;
                    Appreciation appreciation;
                    foreach (var id in articleId)
                    {
                        appreciation           = new Appreciation();
                        appreciation.FormID    = formId;
                        appreciation.ArticleID = id;

                        article = db.Articles.Get(id);
                        appreciation.ArticleName = article.Name;
                        db.Appreciations.Create(appreciation);
                        db.Save();
                    }
                    return(View("FormResult", form));
                }
                else
                {
                    return(View(db.Articles.GetAll().ToList()));
                }
            }
            else
            {
                return(View(db.Articles.GetAll().ToList()));
            }
        }
        protected override void Seed(Coles.Appreciate.Models.ColesAppreciateDataContext context)
        {
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method
            //  to avoid creating duplicate seed data.

            //context.Database.ExecuteSqlCommand("TRUNCATE TABLE [dbo].[Appreciation]");
            //context.Database.ExecuteSqlCommand("TRUNCATE TABLE [dbo].[Status]");
            //context.Database.ExecuteSqlCommand("TRUNCATE TABLE [dbo].[Reason]");
            //context.Database.ExecuteSqlCommand("TRUNCATE TABLE [dbo].[Response]");

            if (context.Appreciations.Count() > 0)
            {
                context.Appreciations.RemoveRange(context.Appreciations);
            }


            if (context.Responses.Count() > 0)
            {
                context.Responses.RemoveRange(context.Responses);
            }


            if (context.Reasons.Count() > 0)
            {
                context.Reasons.RemoveRange(context.Reasons);
            }

            if (context.Responses.Count() > 0)
            {
                context.Status.RemoveRange(context.Status);
            }


            context.SaveChanges();

            context.Reasons.Add(new Reason()
            {
                ReasonText = "dedication"
            });
            context.Reasons.Add(new Reason()
            {
                ReasonText = "inspiring"
            });
            context.Reasons.Add(new Reason()
            {
                ReasonText = "passionate"
            });
            context.Reasons.Add(new Reason()
            {
                ReasonText = "bold"
            });

            context.Responses.Add(new Response()
            {
                ResponseText = "congrats"
            });
            context.Responses.Add(new Response()
            {
                ResponseText = "welldone"
            });
            context.Responses.Add(new Response()
            {
                ResponseText = "impressive"
            });
            context.Responses.Add(new Response()
            {
                ResponseText = "wow"
            });

            context.Status.Add(new Status()
            {
                StatusText = "Edit", StatusCode = 0
            });
            context.Status.Add(new Status()
            {
                StatusText = "Confirmed", StatusCode = 10
            });
            context.Status.Add(new Status()
            {
                StatusText = "Deleted", StatusCode = 99
            });

            context.SaveChanges();

            Status editStatus = context.Status.Where(x => x.StatusCode == 0).Single();

            Console.Write(editStatus.StatusId);

            context.Appreciations.Add(new Appreciation()
            {
                AppreciationText = "GoodWork!", StatusId = editStatus.StatusId
            });
            context.Appreciations.Add(new Appreciation()
            {
                AppreciationText = "Unblieveable!", StatusId = editStatus.StatusId
            });
            context.Appreciations.Add(new Appreciation()
            {
                AppreciationText = "Credit to you!", StatusId = editStatus.StatusId
            });

            context.SaveChanges();

            Appreciation firstAppreciation = context.Appreciations.First();
            Response     firstResponse     = context.Responses.First();
            Reason       firstReason       = context.Reasons.First();

            context.AppreciationAgrees.Add(new AppreciationAgree()
            {
                AppreciationId = firstAppreciation.AppreciationId, ResponseId = firstResponse.ResponseId, UserId = "jsmith"
            });
            context.AppreciationAgrees.Add(new AppreciationAgree()
            {
                AppreciationId = firstAppreciation.AppreciationId, ResponseId = firstResponse.ResponseId, UserId = "mbaker"
            });
            context.AppreciationAgrees.Add(new AppreciationAgree()
            {
                AppreciationId = firstAppreciation.AppreciationId, ResponseId = firstResponse.ResponseId, UserId = "ydocker"
            });

            context.AppreciationReasons.Add(new AppreciationReason()
            {
                AppreciationId = firstAppreciation.AppreciationId, ReasonId = firstReason.ReasonId
            });
            context.AppreciationReasons.Add(new AppreciationReason()
            {
                AppreciationId = firstAppreciation.AppreciationId, ReasonId = firstReason.ReasonId
            });
            context.AppreciationReasons.Add(new AppreciationReason()
            {
                AppreciationId = firstAppreciation.AppreciationId, ReasonId = firstReason.ReasonId
            });

            context.SaveChanges();
        }
Example #23
0
 public void CreateAppreciation(Appreciation appreciation)
 {
     throw new NotImplementedException();
 }
Example #24
0
 public void UpdateAppreciation(Appreciation trajet)
 {
     throw new NotImplementedException();
 }
        public async Task <ActionResult <Appreciation> > DeleteAppreciations(int id)
        {
            // NLog
            string message = $"(API Server) -Try to DELETE an Appreciation " + id + "(Id) - Controller : AppreciationsController; " +
                             "Actionname: DeleteAppreciations(...); HTTP method : HttpDelete; Time: " + DateTime.Now + "\n";

            _logger.Info(message);

            Appreciation appreciation = null;

            try
            {
                // Find Appreciation
                appreciation = await _context.Appreciations.FindAsync(id);

                // Remove Appreciation
                _context.Appreciations.Remove(appreciation);
                await _context.SaveChangesAsync();

                // GET UPDATED DB VALUES
                _context.Entry(appreciation).GetDatabaseValues();
            }
            catch (Exception ex)
            {
                // NLog Framework Call

                // LOG INFO
                _logger.Info("INFORMATION DETAILS, Exception occured during operation : " + message);
                _logger.Info("EXCEPTION DETAILS: " + ex.Message + "\n");

                // LOG WARN
                _logger.Warn("WARNING DETAILS, Exception occured during operation : " + message);
                _logger.Warn("EXCEPTION DETAILS: " + ex.Message + "\n");


                // LOG ERROR
                _logger.Error("ERROR DETAILS, Exception occured during operation : " + message);
                _logger.Error("EXCEPTION DETAILS: " + ex.Message + "\n");


                // LOG TRACE
                _logger.Trace("WARNING DETAILS, Exception occured during operation : " + message);
                _logger.Trace("EXCEPTION DETAILS: " + ex.Message + "\n");


                // LOG FATAL
                _logger.Fatal("FATAL DETAILS, Exception occured during operation : " + message);
                _logger.Fatal("EXCEPTION DETAILS: " + ex.Message + "\n");


                // LOG DEGUG
                _logger.Debug("DEGUG DETAILS, Exception occured during operation : " + message);
                _logger.Debug("EXCEPTION DETAILS: " + ex.Message + "\n");


                if (appreciation == null)
                {
                    return(NotFound());
                }
                else
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
                }
            }

            return(appreciation);
        }
Example #26
0
 public IActionResult Post([FromBody] Appreciation model)
 {
     _context.Appreciations.Add(model);
     _context.SaveChanges();
     return(CreatedAtRoute("GetAppreciation", new { applicationUserID = model.ApplicationUserID, destinationID = model.DestinationID }, model));
 }