public HttpResponseMessage AddOrderDetails(OrderBookingViewModel objOrderBookingViewModel) { try { Mandi_OrderDetails objMandi_OrderDetails = new Mandi_OrderDetails(); MandiUserController objMandiUserController = new MandiUserController(); string mobileNumber = objOrderBookingViewModel.Buyer_Mobile; //get mobileNumber from user table var number = (from user in dbContext.Mandi_UserInfo where user.MobileNumber == mobileNumber select user).FirstOrDefault(); if (number != null && objOrderBookingViewModel.Payment_Mode == "Delivery Against Payment(DAP)") { objMandi_OrderDetails.Buyer_Mobile = objOrderBookingViewModel.Buyer_Mobile; objMandi_OrderDetails.TotalPrice = objOrderBookingViewModel.Totalprice; objMandi_OrderDetails.Payment_Mode = objOrderBookingViewModel.Payment_Mode; objMandi_OrderDetails.OrderDate = DateTime.Now; objMandi_OrderDetails.Shipping_Address_Id = objOrderBookingViewModel.Shipping_Address_Id; objMandi_OrderDetails.Order_Status = objOrderBookingViewModel.Order_Status; objMandi_OrderDetails.GeoAddress = objOrderBookingViewModel.GeoCoordinates; objMandi_OrderDetails.SelectedTotalQty = objOrderBookingViewModel.SelectedTotalQty; objMandi_OrderDetails.TransactionStatus = objOrderBookingViewModel.TransactionStatus; objMandi_OrderDetails.Buyer_Name = objOrderBookingViewModel.Buyer_Name; objMandi_OrderDetails.ServiceTax = objOrderBookingViewModel.ServiceTax; objMandi_OrderDetails.TotalAmount = objOrderBookingViewModel.TotalAmount; dbContext.Mandi_OrderDetails.Add(objMandi_OrderDetails); var i = dbContext.SaveChanges(); int OrderId = objMandi_OrderDetails.Order_Id; // Get OrderId After Save Changes if (i != 0) { objOrderBookingViewModel.Order_Id = OrderId; AddOrderProductDetail(objOrderBookingViewModel); //objMandiUserController.SendFCMNotificationToUsers(number.DeviceToken, "Congratulations…! Your order for amount ₹" + objOrderBookingViewModel.Totalprice + " has been received successfully against Order Id " + objOrderBookingViewModel .Order_Id, "Test"); //AddNotification(objOrderBookingViewModel, "Congratulations…! Your order for amount ₹" + objOrderBookingViewModel.Totalprice + " has been received successfully against Order Id " + objOrderBookingViewModel.Order_Id); #region new notification functionality var getcsvfile = objOrderBookingViewModel.csvfile.Table1; //ntofication and email foreach (var j in getcsvfile) { objMandiUserController.SendFCMNotificationToUsers(number.DeviceToken, "Dear Customer, Your deal of " + j.CropName + "with" + OrderId + " has been booked. Product ID is" + j.Product_Id + " and you have to pick up the produce soon from the pickup address" + j.PickupAddress + ". In case of help, please call on 9607911377.", "Test"); AddNotification(objOrderBookingViewModel, "Dear Customer, Your deal of " + j.CropName + "with" + OrderId + " has been booked.Product ID is " + j.Product_Id + " and you have to pick up the produce soon from the pickup address" + j.PickupAddress + ".In case of help, please call on 9607911377."); var getSellerMobileNumber = (from product in dbContext.Mandi_ProductMaster where product.Tr_Id == j.Product_Id select product.MobileNumber).FirstOrDefault(); if (getSellerMobileNumber != null) { var getSellerTokenNumbner = (from mobile in dbContext.Mandi_UserInfo where mobile.MobileNumber == getSellerMobileNumber select mobile.DeviceToken).FirstOrDefault(); //send notification to seller now objMandiUserController.SendFCMNotificationToUsers(getSellerTokenNumbner, "Dear Customer, Your Produce" + j.CropName + " with" + j.Product_Id + " has been purchased. Order ID is " + OrderId + " and it will soon be picked up. Please keep the products ready. In case of help, please call on 9607911377>.", "Test"); AddNotification(objOrderBookingViewModel, "Dear Customer, Your Produce" + j.CropName + " with" + j.Product_Id + " has been purchased. Order ID is " + OrderId + " and it will soon be picked up. Please keep the products ready. In case of help, please call on 9607911377>."); #region Email to admin //FOR SENDING MAIL TO ADMIN EmailController objEmailController = new EmailController(); EmailModel objEmailModel = new EmailModel(); //objEmailModel.SellerName = objOrderBookingViewModel.SellerName; //objEmailModel.SellerContact = objOrderBookingViewModel.SellerContact; objEmailModel.orderId = OrderId; objEmailModel.ProductId = j.Product_Id; objEmailModel.CropName = j.CropName; objEmailModel.Qty = j.TotalQuantity; // objEmailModel.SellerName = (from mobile in dbContext.Mandi_UserInfo where mobile.MobileNumber == getSellerMobileNumber select mobile.DeviceToken).ToString().FirstOrDefault()); ; objEmailModel.BuyerrName = j.BuyerrName; objEmailModel.BuyerContact = j.BuyerContact; objEmailModel.Price = j.Price; objEmailModel.ServiceTax = j.ServiceTax; objEmailModel.TotalAmount = j.TotalAmount; objEmailModel.PaymentStatus = j.PaymentStatus; objEmailController.sendEmailViaWebApi(objEmailModel); #endregion } } #endregion objOrderResponse.DAP = objOrderBookingViewModel.TotalAmount; return(Request.CreateResponse(HttpStatusCode.OK, objOrderResponse)); } else { objResponse.Message = "Failed"; objMandiUserController.SendFCMNotificationToUsers(number.DeviceToken, "Your order for amount ₹" + objOrderBookingViewModel.Totalprice + " has been Failed against Order Id " + objOrderBookingViewModel.Order_Id, "Test"); AddNotification(objOrderBookingViewModel, "Congratulations…! Your order for amount ₹" + objOrderBookingViewModel.Totalprice + " has been received successfully against Order Id " + objOrderBookingViewModel.Order_Id); return(Request.CreateResponse(HttpStatusCode.OK, objResponse)); } } else if (number != null && objOrderBookingViewModel.Payment_Mode == "UPI") { objMandi_OrderDetails.Buyer_Mobile = objOrderBookingViewModel.Buyer_Mobile; objMandi_OrderDetails.TotalPrice = objOrderBookingViewModel.Totalprice; objMandi_OrderDetails.Payment_Mode = objOrderBookingViewModel.Payment_Mode; objMandi_OrderDetails.OrderDate = DateTime.Now; objMandi_OrderDetails.Shipping_Address_Id = objOrderBookingViewModel.Shipping_Address_Id; objMandi_OrderDetails.Order_Status = objOrderBookingViewModel.Order_Status; objMandi_OrderDetails.GeoAddress = objOrderBookingViewModel.GeoCoordinates; objMandi_OrderDetails.SelectedTotalQty = objOrderBookingViewModel.SelectedTotalQty; objMandi_OrderDetails.Buyer_Name = objOrderBookingViewModel.Buyer_Name; dbContext.Mandi_OrderDetails.Add(objMandi_OrderDetails); var i = dbContext.SaveChanges(); int OrderId = objMandi_OrderDetails.Order_Id; // Get OrderId After Save Changes if (i != 0) { objOrderBookingViewModel.Order_Id = OrderId; AddOrderProductDetail(objOrderBookingViewModel); objMandiUserController.SendFCMNotificationToUsers(number.DeviceToken, "Congratulations…! Your order for amount ₹" + objOrderBookingViewModel.Totalprice + " has been received successfully against Order Id " + objOrderBookingViewModel.Order_Id, "Test"); AddNotification(objOrderBookingViewModel, "Congratulations…! Your order for amount ₹" + objOrderBookingViewModel.Totalprice + " has been received successfully against Order Id " + objOrderBookingViewModel.Order_Id); objResponse.Message = "Success"; objOrderResponse.DAP = ""; objOrderResponse.UPI = objOrderBookingViewModel.Order_Id; return(Request.CreateResponse(HttpStatusCode.OK, objOrderResponse)); } else { objResponse.Message = "Failed"; objMandiUserController.SendFCMNotificationToUsers(number.DeviceToken, "Your order for amount ₹" + objOrderBookingViewModel.Totalprice + " has been Failed against Order Id " + objOrderBookingViewModel.Order_Id, "Test"); return(Request.CreateResponse(HttpStatusCode.OK, objResponse)); } } else { objResponse.Message = "Mobile number not exists."; return(Request.CreateResponse(HttpStatusCode.OK, objResponse)); } } catch (Exception ex) { Log.Info(Convert.ToString(ex.InnerException)); Log.Info(ex.Message); OrderErrorLogDetails objOrderErrorLogDetails = new OrderErrorLogDetails(); objOrderErrorLogDetails.Retailer_Mobile = objOrderBookingViewModel.Buyer_Mobile; objOrderErrorLogDetails.PaymentMode = objOrderBookingViewModel.Payment_Mode; objOrderErrorLogDetails.Total_Price = objOrderBookingViewModel.Totalprice; objOrderErrorLogDetails.Qty = objOrderBookingViewModel.Qty; //objOrderErrorLogDetails.Csv_File =; objOrderErrorLogDetails.Error_Msg = ex.Message; objOrderErrorLogDetails.Tr_Date = DateTime.Now; dbContext.OrderErrorLogDetails.Add(objOrderErrorLogDetails); var i = dbContext.SaveChanges(); if (i != 0) { objResponse.Message = "Exception Logged Successfully"; return(Request.CreateResponse(HttpStatusCode.OK, objResponse)); } else { objResponse.Message = "Failed"; return(Request.CreateResponse(HttpStatusCode.OK, objResponse)); } //objCommonClasses.InsertExceptionDetails(ex, "UserController", "SubmitFeedback"); //return Request.CreateErrorResponse(HttpStatusCode.ExpectationFailed, ex.Message); } }
public HttpResponseMessage UpdateOrderDetails(OrderBookingViewModel objOrderBookingViewModel) { try { Mandi_OrderDetails objMandi_OrderDetails = new Mandi_OrderDetails(); int orderId = Convert.ToInt32(objOrderBookingViewModel.Order_Id); var deviceToken = (from user in dbContext.Mandi_UserInfo where user.MobileNumber == objOrderBookingViewModel.Buyer_Mobile select user.DeviceToken).FirstOrDefault(); //get Order from OrderDetails table var orderDetails = (from order in dbContext.Mandi_OrderDetails where order.Order_Id == orderId select order).FirstOrDefault(); if (orderDetails != null && orderDetails.Payment_Mode == "UPI" && objOrderBookingViewModel.TransactionStatus == "SUCCESS") { orderDetails.TransactionId = objOrderBookingViewModel.TransactionId; orderDetails.ResponseCode = objOrderBookingViewModel.ResponseCode; orderDetails.TransactionStatus = objOrderBookingViewModel.TransactionStatus; var i = dbContext.SaveChanges(); if (i != 0) { MandiUserController objMandiUserController = new MandiUserController(); objMandiUserController.SendFCMNotificationToUsers(deviceToken, "Congratulations…! Your order for amount ₹" + objOrderBookingViewModel.Totalprice + " has been placed successfully against Order Id " + objOrderBookingViewModel.Order_Id, "Test"); AddNotification(objOrderBookingViewModel, "Congratulations…! Your order for amount ₹" + objOrderBookingViewModel.Totalprice + " has been received successfully against Order Id " + objOrderBookingViewModel.Order_Id); #region new notification functionality objMandiUserController.SendFCMNotificationToUsers(deviceToken, "Dear Customer, Your deal of " + objOrderBookingViewModel.CropName + "with" + objOrderBookingViewModel.Order_Id + " has been booked. Product ID is" + objOrderBookingViewModel.ProductId + " and you have to pick up the produce soon from the pickup address" + objOrderBookingViewModel.PickupAddress + ". In case of help, please call on 9607911377.", "Test"); AddNotification(objOrderBookingViewModel, "Dear Customer, Your deal of " + objOrderBookingViewModel.CropName + "with" + objOrderBookingViewModel.Order_Id + " has been booked.Product ID is " + objOrderBookingViewModel.ProductId + " and you have to pick up the produce soon from the pickup address" + objOrderBookingViewModel.PickupAddress + ".In case of help, please call on 9607911377."); var getSellerMobileNumber = (from product in dbContext.Mandi_ProductMaster where product.Tr_Id == objOrderBookingViewModel.ProductId select product.MobileNumber).FirstOrDefault(); if (getSellerMobileNumber != null) { var getSellerTokenNumbner = (from mobile in dbContext.Mandi_UserInfo where mobile.MobileNumber == getSellerMobileNumber select mobile.DeviceToken).FirstOrDefault(); //send notification to seller now objMandiUserController.SendFCMNotificationToUsers(getSellerTokenNumbner, "Dear Customer, Your Produce" + objOrderBookingViewModel.CropName + " with" + objOrderBookingViewModel.ProductId + " has been purchased. Order ID is" + objOrderBookingViewModel.Order_Id + " and it will soon be picked up. Please keep the products ready. In case of help, please call on 9607911377>.", "Test"); AddNotification(objOrderBookingViewModel, "Dear Customer, Your Produce" + objOrderBookingViewModel.CropName + " with" + objOrderBookingViewModel.ProductId + " has been purchased. Order ID is" + objOrderBookingViewModel.Order_Id + " and it will soon be picked up. Please keep the products ready. In case of help, please call on 9607911377>."); #region Email to admin // EmailController objEmailController = new EmailController(); //EmailModel objEmailModel = new EmailModel(); //objEmailModel.orderId = objOrderBookingViewModel.Order_Id; //objEmailModel.ProductId = objOrderBookingViewModel.ProductId; // objEmailController.sendEmailViaWebApi(); #endregion } #endregion objResponse.Message = "Paid Successfully"; return(Request.CreateResponse(HttpStatusCode.OK, objResponse)); } else { objResponse.Message = "Transaction Failed."; return(Request.CreateResponse(HttpStatusCode.OK, objResponse)); } } else if (objOrderBookingViewModel.TransactionStatus == "FAILURE") { orderDetails.TransactionStatus = objOrderBookingViewModel.TransactionStatus; orderDetails.ResponseCode = objOrderBookingViewModel.ResponseCode; var i = dbContext.SaveChanges(); if (i != 0) { objResponse.Message = "Transaction Failed"; MandiUserController objMandiUserController = new MandiUserController(); objMandiUserController.SendFCMNotificationToUsers(deviceToken, "Transaction Declined for amount ₹" + objOrderBookingViewModel.Totalprice + " against Order Id " + objOrderBookingViewModel.Order_Id, "Test"); AddNotification(objOrderBookingViewModel, "Congratulations…! Your order for amount ₹" + objOrderBookingViewModel.Totalprice + " has been received successfully against Order Id " + objOrderBookingViewModel.Order_Id); return(Request.CreateResponse(HttpStatusCode.OK, objResponse)); } else { objResponse.Message = "Error occured While Saving Transaction Status."; return(Request.CreateResponse(HttpStatusCode.OK, objResponse)); } } else { objResponse.Message = "No Order Details Found."; return(Request.CreateResponse(HttpStatusCode.OK, objResponse)); } } catch (Exception ex) { Log.Info(Convert.ToString(ex.InnerException)); Log.Info(ex.Message); objCommonClasses.InsertExceptionDetails(ex, "UserController", "UpdateOrderDetails"); return(Request.CreateErrorResponse(HttpStatusCode.ExpectationFailed, ex.Message)); } }