public ActionResult AssignRole(string username, string rolename) { try { var checkuser = MH.CheckForDatas("UserName", username, null, null, "Authentication", "Authentication"); if (checkuser != null) { var updateRole = MH.UpdateSingleObject(Builders <BsonDocument> .Filter.Eq("UserName", username), "Authentication", "Authentication", Builders <BsonDocument> .Update.Set("UserRole", rolename)); return(Ok(new ResponseData { Code = "200", Message = "Role assigned to user", Data = null })); } else { return(BadRequest(new ResponseData { Code = "404", Message = "User not found", Data = null })); } } catch (Exception ex) { LoggerDataAccess.CreateLog("AdminContoller", "InsertRoles", ex.Message); return(BadRequest(new ResponseData { Code = "400", Message = "Failed", Data = ex.Message })); } }
public async Task <ActionResult> Paymentcancelled(IFormCollection paymentResponse) { if (paymentResponse != null) { string responseHash = paymentResponse["hash"]; PaymentModel paymentModel = new PaymentModel { Email = paymentResponse["email"], OrderId = Convert.ToInt16(paymentResponse["udf1"]), UserName = paymentResponse["udf2"], ProductInfo = paymentResponse["productinfo"], FirstName = paymentResponse["firstname"], Amount = paymentResponse["amount"], }; var updatePaymentMethod = await MH.UpdateSingleObject(Builders <BsonDocument> .Filter.Eq("OrderId", paymentModel.OrderId), "OrderDB", "OrderInfo", Builders <BsonDocument> .Update.Set("PaymentMethod", paymentResponse["mode"].ToString())); PaymentMethod paymentDetails = new PaymentMethod(); List <StatusCode> statusCodeList = new List <StatusCode>(); var orderData = BsonSerializer.Deserialize <OrderInfo>(MH.GetSingleObject(Builders <BsonDocument> .Filter.Eq("OrderId", paymentModel.OrderId), "OrderDB", "OrderInfo").Result); foreach (var detail in orderData.PaymentDetails.Status) { statusCodeList.Add(detail); } statusCodeList.Add(new StatusCode { StatusId = 4, Description = "Payment Cancelled", Date = DateTime.UtcNow }); paymentDetails.Status = statusCodeList; var updatePaymentDetails = await MH.UpdateSingleObject(Builders <BsonDocument> .Filter.Eq("OrderId", paymentModel.OrderId), "OrderDB", "OrderInfo", Builders <BsonDocument> .Update.Set("PaymentDetails", paymentDetails)); return(Redirect(GlobalHelper.ReadXML().Elements("payu").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("redirectcancelled").First().Value)); } else { return(Redirect(GlobalHelper.ReadXML().Elements("payu").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("redirectcancelled").First().Value)); } }
public ActionResult ReturnOrder(string request, int orderid, string productSKU) { if (request == "refund" || request == "replace") { try { var checkData = MH.CheckForDatas("OrderId", orderid, null, null, "OrderDB", "OrderInfo"); if (checkData != null) { var orderDetails = BsonSerializer.Deserialize <OrderInfo>(checkData); if (orderDetails.OrderStatus == "Order Delivered") { foreach (var product in orderDetails.ProductDetails) { if (product.ProductSKU == productSKU) { foreach (var status in product.StatusCode) { if (status.Description == "Order Delivered") { if (DateTime.UtcNow > status.Date.AddDays(15)) { return(BadRequest(new ResponseData { Code = "407", Message = "Return request cannot be processed as it has been more than 15 days from delivery", Data = null })); } } } } } var checkProduct = MH.CheckForDatas("ProductSKU", productSKU, null, null, "ProductDB", "Product"); if (checkProduct != null) { var productData = BsonSerializer.Deserialize <Product>(checkData); if (request == "refund") { if (productData.RefundApplicable == true) { List <ProductDetails> productDetails = new List <ProductDetails>(); foreach (var product in orderDetails.ProductDetails) { if (product.ProductSKU == productSKU) { product.Status = "Order Refund Initiated"; List <StatusCode> statusList = new List <StatusCode>(); foreach (var status in product.StatusCode) { statusList.Add(status); } statusList.Add(new StatusCode { Date = DateTime.UtcNow, StatusId = 8, Description = "Order Refund Initiated" }); } productDetails.Add(product); } var updateProductDetails = MH.UpdateSingleObject(Builders <BsonDocument> .Filter.Eq("OrderId", orderid), "OrderDB", "OrderInfo", Builders <BsonDocument> .Update.Set("ProductDetails", productDetails)).Result; if (updateProductDetails == false) { return(BadRequest(new ResponseData { Code = "408", Message = "Product details status update failed", Data = null })); } //if(orderDetails.PaymentMethod != "COD") //{ //Need to refund amount //} return(Ok(new ResponseData { Code = "201", Message = "Payment Refund Initiated", Data = null })); } else { return(BadRequest(new ResponseData { Code = "403", Message = "Refund not applicable for this product", Data = null })); } } else { if (productData.ReplacementApplicable == true) { List <ProductDetails> productDetails = new List <ProductDetails>(); foreach (var product in orderDetails.ProductDetails) { if (product.ProductSKU == productSKU) { product.Status = "Order Replacement Initiated"; List <StatusCode> statusList = new List <StatusCode>(); foreach (var status in product.StatusCode) { statusList.Add(status); } statusList.Add(new StatusCode { Date = DateTime.UtcNow, StatusId = 6, Description = "Order Replacement Initiated" }); } productDetails.Add(product); } var updateProductDetails = MH.UpdateSingleObject(Builders <BsonDocument> .Filter.Eq("OrderId", orderid), "OrderDB", "OrderInfo", Builders <BsonDocument> .Update.Set("ProductDetails", productDetails)).Result; if (updateProductDetails == false) { return(BadRequest(new ResponseData { Code = "408", Message = "Product details status update failed", Data = null })); } return(Ok(new ResponseData { Code = "202", Message = "Product replacement initiated", Data = null })); } else { return(BadRequest(new ResponseData { Code = "405", Message = "Replacement not applicable for this product", Data = null })); } } } else { return(BadRequest(new ResponseData { Code = "402", Message = "Product not found", Data = null })); } } else { return(BadRequest(new ResponseData { Code = "406", Message = "Return request cannot be processed as the product is not delivered", Data = null })); } } else { return(BadRequest(new ResponseData { Code = "404", Message = "Order not found", Data = null })); } } catch (Exception ex) { LoggerDataAccess.CreateLog("OrderController", "CancelOrder", ex.Message); return(BadRequest(new ResponseData { Code = "400", Message = "Failed", Data = ex.Message })); } } else { return(BadRequest(new ResponseData { Code = "401", Message = "Invalid request", Data = null })); } }
public async Task <ActionResult> PlaceOrder([FromBody] OrderInfo data, string username) { try { IAsyncCursor <Address> userCursor = await _db.GetCollection <Address>("UserInfo").FindAsync(Builders <Address> .Filter.Eq("UserName", username)); var users = userCursor.ToList(); if (users.Count > 0) { IAsyncCursor <Cart> cartCursor = await _db.GetCollection <Cart>("Cart").FindAsync(Builders <Cart> .Filter.Eq("UserName", username)); var cartDatas = cartCursor.ToList(); if (cartDatas.Count > 0) { var ordersCount = order_db.GetCollection <OrderInfo>("OrderInfo").Find(Builders <OrderInfo> .Filter.Empty).Count(); data.OrderId = ordersCount + 1; data.UserName = username; data.PaymentMethod = "Nil"; PaymentMethod paymentMethod = new PaymentMethod(); List <StatusCode> paymentStatus = new List <StatusCode>(); paymentStatus.Add(new StatusCode { Date = DateTime.UtcNow, StatusId = 1, Description = "Payment Initiated" }); paymentMethod.Status = paymentStatus; data.PaymentDetails = paymentMethod; List <Address> addressList = new List <Address>(); foreach (var address in users) { if (address.DefaultAddress == true) { addressList.Add(address); } } data.Address = addressList; if (data.Address.Count == 0) { return(BadRequest(new ResponseData { Code = "404", Message = "No default address found", Data = null })); } List <ProductDetails> productList = new List <ProductDetails>(); foreach (var cart in cartDatas) { foreach (var product in MH.GetProducts(cart.ProductSKU, product_db).Result) { if (product.ProductStock < cart.ProductQuantity) { return(BadRequest(new ResponseData { Code = "403", Message = "Order quantity is higher than the product stock.", Data = null })); } ProductDetails productDetails = new ProductDetails(); productDetails.ProductSKU = cart.ProductSKU; productDetails.Status = "Order Placed"; productDetails.Reviewed = false; List <StatusCode> productStatus = new List <StatusCode>(); productStatus.Add(new StatusCode { StatusId = 1, Date = DateTime.UtcNow, Description = "Order Placed" }); productDetails.StatusCode = productStatus; productDetails.ProductInCart = cart; productList.Add(productDetails); } } data.ProductDetails = productList; data.OrderStatus = "Order Placed"; await order_db.GetCollection <OrderInfo>("OrderInfo").InsertOneAsync(data); List <string> productInfoList = new List <string>(); foreach (var cart in cartDatas) { productInfoList.Add(cart.ProductSKU); } string productInfo = String.Join(":", productInfoList); RegisterModel userInfo = BsonSerializer.Deserialize <RegisterModel>(MH.GetSingleObject(Builders <BsonDocument> .Filter.Eq("UserName", username), "Authentication", "Authentication").Result); Address addressInfo = BsonSerializer.Deserialize <Address>(MH.GetSingleObject(Builders <BsonDocument> .Filter.Eq("UserName", username), "UserInfo", "UserInfo").Result); PaymentModel paymentModel = new PaymentModel { FirstName = userInfo.FullName, UserName = username, LastName = "", ProductInfo = productInfo, Amount = data.TotalAmount.ToString(), Email = userInfo.Email, PhoneNumber = userInfo.PhoneNumber, AddressLine1 = addressInfo.AddressLines, AddressLine2 = addressInfo.Landmark, City = addressInfo.City, State = addressInfo.State, Country = userInfo.UserLocation, ZipCode = addressInfo.PinCode, OrderId = data.OrderId }; if (data.TotalAmount == 0) { var updatePaymentMethod = await MH.UpdateSingleObject(Builders <BsonDocument> .Filter.Eq("OrderId", paymentModel.OrderId), "OrderDB", "OrderInfo", Builders <BsonDocument> .Update.Set("PaymentMethod", "Coupon")); var updatePaymentDetails = await MH.UpdatePaymentDetails(paymentModel.OrderId); var removecartItems = await MH.RemoveCartItems(paymentModel.OrderId, paymentModel.UserName, paymentModel.Email); var sendGift = GlobalHelper.SendGift(paymentModel.OrderId); return(Ok(new ResponseData { Code = "201", Message = "Payment success", Data = null })); } else { var hashtableData = PayUHelper.GetHashtableData(paymentModel); return(Ok(new ResponseData { Code = "200", Message = "Order Placed", Data = hashtableData })); } } else { return(BadRequest(new ResponseData { Code = "402", Message = "Cart not found", Data = null })); } } else { return(BadRequest(new ResponseData { Code = "401", Message = "UserInfo not found", Data = null })); } } catch (Exception ex) { LoggerDataAccess.CreateLog("OrderController", "PlaceOrder", ex.Message); return(BadRequest(new ResponseData { Code = "400", Message = "Failed", Data = ex.Message })); } }
public ActionResult CancelOrder(int orderid, string productSKU) { try { var checkData = MH.CheckForDatas("OrderId", orderid, null, null, "OrderDB", "OrderInfo"); if (checkData != null) { var orderDetails = BsonSerializer.Deserialize <OrderInfo>(checkData); if (MH.CheckForDatas("ProductSKU", productSKU, null, null, "ProductDB", "Product") != null) { List <ProductDetails> productDetails = new List <ProductDetails>(); foreach (var product in orderDetails.ProductDetails) { if (product.ProductSKU == productSKU) { if (product.Status == "Order Delivered") { return(BadRequest(new ResponseData { Code = "401", Message = "Cancel request cannot be processed as the product is delivered", Data = null })); } else if (product.Status == "Order Cancelled") { return(BadRequest(new ResponseData { Code = "402", Message = "Order already cancelled", Data = null })); } else if (product.Status == "Order Replaced" || orderDetails.OrderStatus == "Order Refunded") { return(BadRequest(new ResponseData { Code = "403", Message = "Cancel request cannot be processed as the order status is " + orderDetails.OrderStatus, Data = null })); } product.Status = "Order Cancelled"; List <StatusCode> statusCode = new List <StatusCode>(); foreach (var status in product.StatusCode) { statusCode.Add(status); } statusCode.Add(new StatusCode { Date = DateTime.UtcNow, StatusId = 4, Description = "Order Cancelled" }); product.StatusCode = statusCode; } productDetails.Add(product); } var updateOrderStatus = MH.UpdateSingleObject(Builders <BsonDocument> .Filter.Eq("OrderId", orderid), "OrderDB", "OrderInfo", Builders <BsonDocument> .Update.Set("OrderStatus", "Order Cancelled")).Result; if (updateOrderStatus == false) { return(BadRequest(new ResponseData { Code = "405", Message = "Order status update failed", Data = null })); } var updateProductDetails = MH.UpdateSingleObject(Builders <BsonDocument> .Filter.Eq("OrderId", orderid), "OrderDB", "OrderInfo", Builders <BsonDocument> .Update.Set("ProductDetails", productDetails)).Result; if (updateProductDetails == false) { return(BadRequest(new ResponseData { Code = "406", Message = "Order cancelled status update failed", Data = null })); } //if(orderDetails.PaymentMethod != "COD") //{ //Need to refund amount //} return(Ok(new ResponseData { Code = "200", Message = "Order cancelled", Data = null })); } else { return(BadRequest(new ResponseData { Code = "407", Message = "Product not found", Data = null })); } } else { return(BadRequest(new ResponseData { Code = "404", Message = "Order not found", Data = null })); } } catch (Exception ex) { LoggerDataAccess.CreateLog("OrderController", "CancelOrder", ex.Message); return(BadRequest(new ResponseData { Code = "400", Message = "Failed", Data = ex.Message })); } }
public ActionResult UpdateDeliveryStatus(int orderid, string status) { try { var checkData = MH.CheckForDatas("OrderId", orderid, null, null, "OrderDB", "OrderInfo"); if (checkData != null) { var orderDetails = BsonSerializer.Deserialize <OrderInfo>(checkData); if (status != "Order Replaced" || status != "Order Refunded") { var updateOrderStatus = MH.UpdateSingleObject(Builders <BsonDocument> .Filter.Eq("OrderId", orderid), "OrderDB", "OrderInfo", Builders <BsonDocument> .Update.Set("OrderStatus", status)).Result; if (updateOrderStatus == false) { return(BadRequest(new ResponseData { Code = "401", Message = "Order status update failed", Data = null })); } } List <ProductDetails> productDetails = new List <ProductDetails>(); foreach (var product in orderDetails.ProductDetails) { product.Status = status; List <StatusCode> statusList = new List <Data.StatusCode>(); foreach (var data in product.StatusCode) { statusList.Add(data); } int statusId = 0; if (status == "Packing In Progress") { statusId = 2; } else if (status == "Order Shipped") { statusId = 3; } else if (status == "Order Delivered") { statusId = 5; } else if (status == "Order Replaced") { statusId = 7; } else if (status == "Order Refunded") { statusId = 9; } statusList.Add(new StatusCode { StatusId = statusId, Date = DateTime.UtcNow, Description = status }); product.StatusCode = statusList; productDetails.Add(product); } var updateProductDetails = MH.UpdateSingleObject(Builders <BsonDocument> .Filter.Eq("OrderId", orderid), "OrderDB", "OrderInfo", Builders <BsonDocument> .Update.Set("ProductDetails", productDetails)).Result; if (updateProductDetails == false) { return(BadRequest(new ResponseData { Code = "402", Message = "Product details order status update failed", Data = null })); } return(Ok(new ResponseData { Code = "200", Message = "Status updated", Data = null })); } else { return(BadRequest(new ResponseData { Code = "404", Message = "Order not found", Data = null })); } } catch (Exception ex) { LoggerDataAccess.CreateLog("OrderController", "UpdateDeliveryStatus", ex.Message); return(BadRequest(new ResponseData { Code = "400", Message = "Failed", Data = ex.Message })); } }
public async Task <ActionResult> PaymentSuccess(IFormCollection paymentResponse) { if (paymentResponse != null) { PaymentModel paymentModel = new PaymentModel { Email = paymentResponse["email"], OrderId = Convert.ToInt16(paymentResponse["udf1"]), UserName = paymentResponse["udf2"], ProductInfo = paymentResponse["productinfo"], FirstName = paymentResponse["firstname"], Amount = paymentResponse["amount"], }; try { if (PU.Generatehash512(PU.GetReverseHashString(paymentResponse["txnid"], paymentModel)) == paymentResponse["hash"]) { var updatePaymentMethod = await MH.UpdateSingleObject(Builders <BsonDocument> .Filter.Eq("OrderId", paymentModel.OrderId), "OrderDB", "OrderInfo", Builders <BsonDocument> .Update.Set("PaymentMethod", paymentResponse["mode"].ToString())); var updatePaymentDetails = await MH.UpdatePaymentDetails(paymentModel.OrderId); var removeCartItems = MH.RemoveCartItems(paymentModel.OrderId, paymentModel.UserName, paymentModel.Email); var sendGift = GlobalHelper.SendGift(paymentModel.OrderId); var sendProductDetails = EmailHelper.SendEmail_ProductDetails(paymentModel.Email, paymentModel.OrderId); return(Redirect(GlobalHelper.ReadXML().Elements("payu").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("redirectsuccess").First().Value)); } else { var updatePaymentMethod = await MH.UpdateSingleObject(Builders <BsonDocument> .Filter.Eq("OrderId", paymentModel.OrderId), "OrderDB", "OrderInfo", Builders <BsonDocument> .Update.Set("PaymentMethod", paymentResponse["mode"].ToString())); PaymentMethod paymentDetails = new PaymentMethod(); List <StatusCode> statusCodeList = new List <StatusCode>(); var orderData = BsonSerializer.Deserialize <OrderInfo>(MH.GetSingleObject(Builders <BsonDocument> .Filter.Eq("OrderId", paymentModel.OrderId), "OrderDB", "OrderInfo").Result); foreach (var detail in orderData.PaymentDetails.Status) { statusCodeList.Add(detail); } statusCodeList.Add(new StatusCode { StatusId = 3, Description = "Payment Failed", Date = DateTime.UtcNow }); paymentDetails.Status = statusCodeList; var updatePaymentDetails = await MH.UpdateSingleObject(Builders <BsonDocument> .Filter.Eq("OrderId", paymentModel.OrderId), "OrderDB", "OrderInfo", Builders <BsonDocument> .Update.Set("PaymentDetails", paymentDetails)); return(Redirect(GlobalHelper.ReadXML().Elements("payu").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("redirectfailure").First().Value)); } } catch (Exception ex) { LoggerDataAccess.CreateLog("PaymentController", "PaymentSuccess", ex.Message); var updatePaymentMethod = await MH.UpdateSingleObject(Builders <BsonDocument> .Filter.Eq("OrderId", paymentModel.OrderId), "OrderDB", "OrderInfo", Builders <BsonDocument> .Update.Set("PaymentMethod", paymentResponse["mode"].ToString())); PaymentMethod paymentDetails = new PaymentMethod(); List <StatusCode> statusCodeList = new List <StatusCode>(); var orderData = BsonSerializer.Deserialize <OrderInfo>(MH.GetSingleObject(Builders <BsonDocument> .Filter.Eq("OrderId", paymentModel.OrderId), "OrderDB", "OrderInfo").Result); foreach (var detail in orderData.PaymentDetails.Status) { statusCodeList.Add(detail); } statusCodeList.Add(new StatusCode { StatusId = 3, Description = "Payment Failed", Date = DateTime.UtcNow }); paymentDetails.Status = statusCodeList; var updatePaymentDetails = await MH.UpdateSingleObject(Builders <BsonDocument> .Filter.Eq("OrderId", paymentModel.OrderId), "OrderDB", "OrderInfo", Builders <BsonDocument> .Update.Set("PaymentDetails", paymentDetails)); return(Redirect(GlobalHelper.ReadXML().Elements("payu").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("redirectfailure").First().Value)); } } else { return(Redirect(GlobalHelper.ReadXML().Elements("payu").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("redirectfailure").First().Value)); } }