Exemple #1
0
        public TourAdvance InsertTour(TourAdvance tourAdvance, out string errorMessage)
        {
            try
            {
                // var date = DateTime.ParseExact(tourAdvance.FromJourneyDate, "dd/MM/yyyy hh:mm:ss tt", null).ToString("dd/MM/yyyy hh:mm:ss tt");
                errorMessage = string.Empty;

                using (MobileContext context = new MobileContext())
                {
                    //var _count = context.TourAdvance.AsEnumerable()
                    //                    .Where(x =>COnver(tourAdvance.FromJourneyDate, "dd/MM/yyyy hh:mm:ss tt", null) >= DateTime.ParseExact(tourAdvance.FromJourneyDate, "dd/MM/yyyy hh:mm:ss tt", null)
                    //                                               && tourAdvance.EmpCode == tourAdvance.EmpCode).Count();

                    //if (_count > 0)
                    //{
                    //    errorMessage = "Same journey alrady applied";
                    //    return null;
                    //}


                    tourAdvance.Status          = STATUS.NEW.ToString();
                    tourAdvance.ApplyDate       = (DateTime.Now);
                    tourAdvance.FromJourneyDate = tourAdvance.FromJourneyDate;
                    tourAdvance.ToJourneyDate   = tourAdvance.ToJourneyDate;
                    context.TourAdvance.Add(tourAdvance);
                    if (context.SaveChanges() > 0)
                    {
                        return(tourAdvance);
                    }

                    return(null);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public async Task <IActionResult> CreateToure([FromBody] TourAdvance tourAdvance)
        {
            if (tourAdvance == null)
            {
                return(Ok(new APIResponse()
                {
                    STATUS = APISTATUS.FAIL.ToString(), Response = "Request is empty."
                }));
            }

            try
            {
                string errorMEssage = string.Empty;

                var result = new TouresHelper().InsertTour(tourAdvance, out errorMEssage);
                if (result != null)
                {
                    return(Ok(new APIResponse()
                    {
                        STATUS = APISTATUS.PASS.ToString(), Response = result
                    }));
                }

                return(Ok(new APIResponse()
                {
                    STATUS = APISTATUS.FAIL.ToString(), Response = errorMEssage
                }));
            }
            catch (Exception ex)
            {
                return(Ok(new APIResponse()
                {
                    STATUS = APISTATUS.FAIL.ToString(), Response = ex.InnerException == null ? ex.Message : ex.InnerException.Message
                }));
            }
        }