public IHttpActionResult PutBStage(int id, BStage bStage)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BStageExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Example #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            BStage bStage = db.BStages.Find(id);

            db.BStages.Remove(bStage);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #3
0
 public ActionResult Edit([Bind(Include = "id,FullReference,Status,FromDate,ToDate,Consultant,Sales_Update")] BStage bStage)
 {
     if (ModelState.IsValid)
     {
         db.Entry(bStage).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(bStage));
 }
        public IHttpActionResult GetBStage(int id)
        {
            BStage bStage = db.BStages.Find(id);

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

            return(Ok(bStage));
        }
Example #5
0
        public ActionResult Create([Bind(Include = "id,FullReference,Status,FromDate,ToDate,Consultant,Sales_Update")] BStage bStage)
        {
            if (ModelState.IsValid)
            {
                db.BStages.Add(bStage);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(bStage));
        }
        public IHttpActionResult PostBStage(BStage bStage)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.BStages.Add(bStage);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = bStage.id }, bStage));
        }
        public IHttpActionResult DeleteBStage(int id)
        {
            BStage bStage = db.BStages.Find(id);

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

            db.BStages.Remove(bStage);
            db.SaveChanges();

            return(Ok(bStage));
        }
Example #8
0
        // GET: BStagesMVC3/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BStage bStage = db.BStages.Find(id);

            if (bStage == null)
            {
                return(HttpNotFound());
            }
            return(View(bStage));
        }
        public static Dictionary <string, List <BStage> > UpdateBStages(IEnumerable <BookingMini> listBookingMini, string APIcompanyDB, IEnumerable <BStage> listBStage)
        {
            //      the BStage in the company db have to be continous in order not to add days in between in case of a booking reverted to a previous status
            //      relationship between listBookingMini and listBStage is of One to 0-Many
            //  comparison between a BookingMini and its last(to keep the continuity) BStage
            //      2 possible cases :
            //          1) existing BStage
            //            -> update the field "ToDate" of the corresponding BStage in the company db
            //                 API PUT
            //           2) new BStage
            //           -> create the new BStage in the company db
            //                API POST


            // 26/04/2017: APItraceSuccess
            //      will have following information available for the homepage
            //          list of booking where the API was successful:
            //              list of BStages updated in the company db
            //              list of BStages added in the company db
            //          list of the booking where the API was unsuccessful



            //  keep a trace of the succesfull or unsuccessful POST/PUT
            Dictionary <string, List <BStage> > APItraceSuccess = new Dictionary <string, List <BStage> >();

            APItraceSuccess.Add("updatedBookingStages", new List <BStage>());
            APItraceSuccess.Add("addedBookingStages", new List <BStage>());
            APItraceSuccess.Add("unsuccessfulAPICall", new List <BStage>());


            using (HttpClient client = new HttpClient())
            {
                client.BaseAddress = new Uri(APIcompanyDB);

                foreach (BookingMini bm in listBookingMini)
                {
                    bool NewBStage = false;

                    BStage bs = listBStage.Where(_bs => _bs.BHD_ID == bm.BHD_ID).OrderBy(_bs => _bs.ToDate).LastOrDefault();

                    BStage APItransferedBS = new BStage()
                    {
                        FullReference = bm.FullReference, Consultant = bm.Consultant, Sales_Update = bm.Sales_Update, Status = bm.Status, ToDate = DateTime.Today, BHD_ID = bm.BHD_ID
                    };

                    if (bs == null)
                    {
                        // when the full reference appears for the first time
                        APItransferedBS.FromDate = bm.Date_Entered;
                        NewBStage = true;
                    }
                    else
                    {
                        // equality evaluation:
                        foreach (PropertyInfo p in typeof(BookingMini).GetProperties())
                        {
                            // if one value of the string properties is different NewBStage = true and break the for loop
                            if (p.PropertyType.Name == "String")
                            {
                                if (typeof(BStage).GetProperty(p.Name).GetValue(bs).ToString().Trim() != p.GetValue(bm).ToString().Trim())
                                {
                                    NewBStage = true;
                                    APItransferedBS.FromDate = DateTime.Today;
                                    break;
                                }
                            }
                        }
                    }

                    Task <HttpResponseMessage> apiTask;
                    if (NewBStage)
                    {                        // POST
                        apiTask = client.PostAsJsonAsync <BStage>("BStages", APItransferedBS);
                    }
                    else
                    {                        // PUT
                        // the only change is the last date of the booking stage
                        APItransferedBS        = bs;
                        APItransferedBS.ToDate = DateTime.Today;
                        apiTask = client.PutAsJsonAsync <BStage>($"BStages/{APItransferedBS.id}", APItransferedBS);
                    }

                    try
                    {
                        apiTask.Wait();
                        HttpResponseMessage result = apiTask.Result;
                        if (result.IsSuccessStatusCode)
                        {
                            if (NewBStage)
                            {
                                APItraceSuccess["addedBookingStages"].Add(APItransferedBS);
                            }
                            else
                            {
                                APItraceSuccess["updatedBookingStages"].Add(APItransferedBS);
                            }
                        }
                        else
                        {
                            APItraceSuccess["unsuccessfulAPICall"].Add(APItransferedBS);
                        }
                    }
                    catch (System.AggregateException)
                    {
                        APItraceSuccess["unsuccessfulAPICall"].Add(APItransferedBS);
                    }
                }
            }

            return(APItraceSuccess);
        }