public IHttpActionResult PostUser_Trips(User_Trips user_Trips) { //bool cb = true; //sagar code bool cb = false; //sachin code if (cb) { //User_Trips user_Trips = new User_Trips(); //user_Trips.tripStartLocation = source; //user_Trips.tripEndLocation = destination; //user_Trips.tripDate =Convert.ToDateTime(startdate); bool flag = false; IQueryable <User_Trips> result = db.User_Trips.Where(l => l.userid == user_Trips.userid); User_Trips[] utrips = result.ToArray(); foreach (var item in utrips) { if (user_Trips.tripStartLocation == item.tripStartLocation && user_Trips.tripEndLocation == item.tripEndLocation) { flag = true; item.tripDate = user_Trips.tripDate; item.tripEndDate = user_Trips.tripEndDate; item.CreatedDate = System.DateTime.Now; db.SaveChanges(); } } if (flag == false) { user_Trips.CreatedDate = DateTime.Now; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.User_Trips.Add(user_Trips); db.SaveChanges(); } } else { int? uid = user_Trips.userid; string src = user_Trips.tripStartLocation; string dest = user_Trips.tripEndLocation; decimal? tripamt = user_Trips.totalCost; string tt = "single"; string vehicleno = user_Trips.userVechicleNumber; string vehicleType = db.User_Vehicle.Where(p => p.uservehicleRegNo == vehicleno).FirstOrDefault().uservehicleType; string pm = "wallet"; string POSDetails = "wallet"; DateTime?stdate = user_Trips.tripDate; DateTime?enddate = user_Trips.tripEndDate; string resulttolllist = db.RouteTollsQueries.Where(r => r.src.Contains(src) && r.dest.Contains(dest)).FirstOrDefault().routetolls; // db.CreateTrip(#ut.userid, #ut.tripStartLocation, #ut.tripEndLocation, #resulttolllist, #TripTotalAmount, #pm, //#TxtPOSDetails.Text, #TxtPOSDetails.Text, #TxtPOSDetails.Text, ut.userVechicleNumber, vt, tt, ut.tripDate, ut.tripEndDate); int rid = db.CreateTrip(uid, src, dest, resulttolllist, tripamt, pm, POSDetails, POSDetails, POSDetails, vehicleno, vehicleType, tt, stdate, enddate, user_Trips.DriverMobileNo, user_Trips.DriverOwnerMobNo); string smsmsg; smsmsg = "Dear Customer, Rs. " + tripamt + " Paid via " + POSDetails + "for Trip Src-" + src + "Dest- " + dest; ns.sendsms("smsfrom", user_Trips.DriverMobileNo, smsmsg); string userEmail = db.Users.Where(o => o.srno == uid).FirstOrDefault().userEmail; ns.sendemail(userEmail, "", "TollPay.IN Trip Booked", smsmsg); } return(CreatedAtRoute("DefaultApi", new { id = user_Trips.srno }, user_Trips)); }