예제 #1
0
        public async Task <MealsGetRes> GetMealsDetailsByQRFID(QuoteGetReq objQuoteGetReq, string ticket)
        {
            MealsGetRes objMealsGetRes = new MealsGetRes();

            objMealsGetRes = await serviceProxy.PostData(_configuration.GetValue <string>("ServiceMeals:GetMealsDetailsByQRFID"), objQuoteGetReq, typeof(MealsGetRes), ticket);

            return(objMealsGetRes);
        }
예제 #2
0
        public async Task <MealsGetRes> GetMealsDetailsByQRFID(QuoteGetReq request)
        {
            var response = new MealsGetRes();
            List <MealDetails> objMealsProperties = new List <MealDetails>();

            RoutingGetReq req = new RoutingGetReq();

            req.QRFId = request.QRFID;

            var resultQuote = _MongoContext.mQuote.AsQueryable().Where(q => q.QRFID == request.QRFID);

            if (resultQuote != null && resultQuote.Count() > 0)
            {
                var resultPosition = _MongoContext.mPosition.AsQueryable().Where(q => q.QRFID == request.QRFID).FirstOrDefault();
                List <RoutingInfo> lstRoutingInfo = await _quoteRepository.GetQRFRouteDetailsByQRFID(req);

                if (resultPosition != null)
                {
                    var result = resultPosition.Meals;
                    if (result != null && result.Count > 0)
                    {
                        var CityCount = result.GroupBy(m => new { m.CityID }).Select(m => new { m.Key.CityID, DayCount = m.Count() });

                        if ((lstRoutingInfo != null && lstRoutingInfo.Count > 0) && (CityCount != null && CityCount.Count() > 0))
                        {
                            result.ToList().FindAll(f => !lstRoutingInfo.Exists(r => r.ToCityID == f.CityID)).ForEach(c => c.IsDeleted = true);

                            foreach (var item in lstRoutingInfo)
                            {
                                int daycount = CityCount.Where(c => c.CityID == item.ToCityID).Select(c => c.DayCount).FirstOrDefault();
                                if (item.Days > daycount)
                                {
                                    // int i = item.Days - daycount; //5-3=2
                                    for (int j = daycount; j < item.Days; j++)
                                    {
                                        result.Add(new MealDetails {
                                            CityID = item.ToCityID, CityName = item.ToCityName, VenueTypes = new List <VenueTypes>()
                                        });
                                    }
                                }
                                else if (item.Days < daycount)
                                {
                                    int i = daycount - item.Days; //5-3=2
                                    result.Where(r => r.CityID == item.ToCityID).TakeLast(i).ToList().ForEach(m => { m.IsDeleted = true; });
                                }
                            }
                            TimeSpan timeoutprev;
                            foreach (var m in result)
                            {
                                m.SequenceNo = lstRoutingInfo.Where(r => r.ToCityID == m.CityID).Select(t => t.RouteSequence).FirstOrDefault();
                                AccomodationInfo objAccomodationInfo = resultPosition.AccomodationInfo.Where(a => a.StartingFrom == m.DayID && a.IsDeleted == false).FirstOrDefault();
                                if (objAccomodationInfo != null)
                                {
                                    MealDetails md = CheckDefaultMealPlan(m, timeoutprev, objAccomodationInfo, out TimeSpan newtimeout);
                                    m.Breakfast   = md.Breakfast;
                                    m.DefaultPlan = md.DefaultPlan;
                                    m.Dinner      = md.Dinner;
                                    m.Lunch       = md.Lunch;
                                    timeoutprev   = newtimeout;
                                }
                            }
                            result = result.Where(m => m.IsDeleted == false).OrderBy(m => m.SequenceNo).ToList();

                            int k = 1;
                            result.ForEach(m => m.DayID    = "Day " + (k++));
                            response.MealDetails           = result;
                            response.ResponseStatus.Status = "Success";
                        }
                        else if ((lstRoutingInfo != null && lstRoutingInfo.Count > 0) && CityCount.Count() == 0)
                        {
                            mPosition objPosition = AddMealsDetails(objMealsProperties, lstRoutingInfo, request, resultPosition.AccomodationInfo, "i");
                            result = objPosition.Meals;

                            var resultFlag = await _MongoContext.mPosition.UpdateOneAsync(Builders <mPosition> .Filter.Eq("QRFID", request.QRFID),
                                                                                          Builders <mPosition> .Update.Set("Meals", result));

                            response.ResponseStatus.Status       = resultFlag.MatchedCount > 0 ? "Success" : "Failure";
                            response.ResponseStatus.ErrorMessage = resultFlag.MatchedCount > 0 ? "Saved Successfully." : "Meals Details not updated.";
                        }
                        else
                        {
                            TimeSpan timeoutprev;
                            var      agentroute = resultQuote.FirstOrDefault().RoutingInfo.FirstOrDefault();
                            result.ForEach(m =>
                            {
                                m.IsDeleted  = true; m.EditDate = agentroute.EditDate; m.EditUser = request.UserName;
                                m.SequenceNo = lstRoutingInfo.Where(r => r.ToCityID == m.CityID).Select(t => t.RouteSequence).FirstOrDefault();
                                AccomodationInfo objAccomodationInfo = resultPosition.AccomodationInfo.Where(a => a.StartingFrom == m.DayID && a.IsDeleted == false).FirstOrDefault();
                                if (objAccomodationInfo != null)
                                {
                                    MealDetails md = CheckDefaultMealPlan(m, timeoutprev, objAccomodationInfo, out TimeSpan newtimeout);
                                    m.Breakfast    = md.Breakfast;
                                    m.DefaultPlan  = md.DefaultPlan;
                                    m.Dinner       = md.Dinner;
                                    m.Lunch        = md.Lunch;
                                    timeoutprev    = newtimeout;
                                }
                            });

                            UpdateResult resultFlag = await _MongoContext.mPosition.UpdateOneAsync(Builders <mPosition> .Filter.Eq("QRFID", request.QRFID),
                                                                                                   Builders <mPosition> .Update.Set("Meals", result));

                            response.ResponseStatus.Status       = resultFlag.MatchedCount > 0 ? "Success" : "Failure";
                            response.ResponseStatus.ErrorMessage = resultFlag.MatchedCount > 0 ? "Saved Successfully." : "Meals Details not updated.";
                        }
                    }
                    else
                    {
                        UpdateResult resultFlag = null;
                        if (lstRoutingInfo != null && lstRoutingInfo.Count > 0)
                        {
                            mPosition objPosition = AddMealsDetails(objMealsProperties, lstRoutingInfo, request, resultPosition.AccomodationInfo, "i");

                            resultFlag = await _MongoContext.mPosition.UpdateOneAsync(Builders <mPosition> .Filter.Eq("QRFID", request.QRFID),
                                                                                      Builders <mPosition> .Update.Set("Meals", objPosition.Meals));

                            response.MealDetails                 = objPosition.Meals;
                            response.ResponseStatus.Status       = resultFlag.MatchedCount > 0 ? "Success" : "Failure";
                            response.ResponseStatus.ErrorMessage = resultFlag.MatchedCount > 0 ? "Saved Successfully." : "Meals Details not updated.";
                        }
                        else
                        {
                            response.ResponseStatus.ErrorMessage = "No Routing Details found.";
                            response.ResponseStatus.Status       = "Failure";
                        }
                    }
                }
                else
                {
                    if (lstRoutingInfo != null && lstRoutingInfo.Count > 0)
                    {
                        mPosition objPosition = AddMealsDetails(objMealsProperties, lstRoutingInfo, request, resultPosition.AccomodationInfo, "i");

                        await _MongoContext.mPosition.InsertOneAsync(objPosition);

                        response.ResponseStatus.Status = "Success";
                        response.MealDetails           = objPosition.Meals;
                    }
                    else
                    {
                        response.ResponseStatus.ErrorMessage = "No Routing Details found.";
                        response.ResponseStatus.Status       = "Failure";
                    }
                }
            }
            else
            {
                response.ResponseStatus.Status       = "Failure";
                response.ResponseStatus.ErrorMessage = "QRFID is not exists.";
            }
            return(response);
        }