public void Helper_Mongo_GetSingleObjectInGB() { //Arrange var dbName = "UnitTestDB"; var collectionName = "Product"; var productFor = "Mens"; var productType = "Shirts"; MongoHelper helper = new MongoHelper(); //Act var filter = Builders <BsonDocument> .Filter.Eq("ProductFor", productFor) & Builders <BsonDocument> .Filter.Eq("ProductType", productType); var result = MOH.GetSingleObject(filter, dbName, collectionName); //Assert Assert.IsNotNull(result.Result); //Assert.AreEqual(result.Result,); }
public ActionResult GetRoleDetailByName(string rolename) { try { var getRole = MH.GetSingleObject(Builders <BsonDocument> .Filter.Eq("RoleName", rolename), "RolesDB", "Roles").Result; if (getRole != null) { var roleInfo = BsonSerializer.Deserialize <Roles>(getRole); return(Ok(new ResponseData { Code = "200", Message = "Success", Data = roleInfo })); } else { return(BadRequest(new ResponseData { Code = "404", Message = "No role found with specified role name", Data = null })); } } catch (Exception ex) { LoggerDataAccess.CreateLog("AdminContoller", "GetRoleDetailByName", 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 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 GetAllUsers() { try { var getlist = MH.GetListOfObjects(null, null, null, null, null, null, "Authentication", "Authentication").Result; if (getlist != null) { List <UserInfomation> userList = new List <UserInfomation>(); foreach (var user in getlist) { var userInfo = BsonSerializer.Deserialize <RegisterModel>(user); var billingAddressData = MH.GetSingleObject(Builders <BsonDocument> .Filter.Eq("UserName", userInfo.UserName) & Builders <BsonDocument> .Filter.Eq("BillingAddress", true), "UserInfo", "UserInfo").Result; Address billingAddress = new Address(); if (billingAddressData != null) { billingAddress = BsonSerializer.Deserialize <Address>(billingAddressData); } else { billingAddress = null; } var shippingAddressData = MH.GetSingleObject(Builders <BsonDocument> .Filter.Eq("UserName", userInfo.UserName) & Builders <BsonDocument> .Filter.Eq("ShippingAddress", true), "UserInfo", "UserInfo").Result; Address shippingAddress = new Address(); if (shippingAddressData != null) { shippingAddress = BsonSerializer.Deserialize <Address>(shippingAddressData); } else { shippingAddress = null; } UserInfomation userInfomation = new UserInfomation { FullName = userInfo.FullName, PhoneNumber = userInfo.PhoneNumber, Email = userInfo.Email, BillingAddress = billingAddress, ShippingAddress = shippingAddress }; userList.Add(userInfomation); } return(Ok(new ResponseData { Code = "200", Message = "Success", Data = userList })); } else { return(BadRequest(new ResponseData { Code = "404", Message = "No users found", Data = null })); } } catch (Exception ex) { LoggerDataAccess.CreateLog("AdminContoller", "GetAllUsers", ex.Message); return(BadRequest(new ResponseData { Code = "400", Message = "Failed", Data = ex.Message })); } }
/// <summary>Send gift by email</summary> /// <param name="orderId">Id of order</param> /// <param name="productInfo">Info of product</param> public static async Task <string> SendGift(long orderId, string productInfo) { try { var productArray = productInfo.Split(":"); var checkOrder = MongoHelper.GetSingleObject(Builders <BsonDocument> .Filter.Eq("OrderId", orderId), "OrderDB", "OrderInfo").Result; if (checkOrder != null) { var orderInfo = BsonSerializer.Deserialize <OrderInfo>(checkOrder); foreach (var product in productArray) { if (product.Contains("Gifts")) { foreach (var info in orderInfo.ProductDetails) { if (product == info.ProductSKU) { Random generator = new Random(); var couponCode = "CU" + generator.Next(0, 1000000).ToString("D6"); Coupon coupon = new Coupon { Code = couponCode, ApplicableFor = "All", UsageCount = 1, Percentage = false, Value = info.ProductInCart.ProductPrice, ExpiryTime = DateTime.UtcNow.AddYears(10) }; //Insert coupon to db await MongoHelper._client.GetDatabase("CouponDB").GetCollection <Coupon>("Coupon").InsertOneAsync(coupon); var user = MongoHelper.GetSingleObject(Builders <BsonDocument> .Filter.Eq("UserName", orderInfo.UserName), "Authentication", "Authentication").Result; if (user == null) { return("User not found"); } var userData = BsonSerializer.Deserialize <RegisterModel>(user); string emailSender = GlobalHelper.ReadXML().Elements("email").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("emailsender").First().Value; using (var client = new AmazonSimpleEmailServiceClient(GetCredentials("accesskey"), GetCredentials("secretkey"), Amazon.RegionEndpoint.USWest2)) { var sendRequest = new SendEmailRequest { Source = emailSender, Destination = new Destination { ToAddresses = new List <string> { info.ProductInCart.ProductFor } }, Message = new Message { Subject = new Content(GlobalHelper.ReadXML().Elements("email").Where(x => x.Element("current").Value.Equals("Yes")).Descendants("emailsubject4").First().Value), Body = new Body { Html = new Content(CreateEmailBody_SendGiftCard(info.ProductInCart.ProductPrice.ToString(), couponCode, info.ProductInCart.ProductDescription, userData.FullName, info.ProductSKU)) } } }; var responce = await client.SendEmailAsync(sendRequest); } } } } } return("Success"); } else { return("Order info not found"); } } catch (Exception ex) { LoggerDataAccess.CreateLog("EmailHelper", "SendGiftCard", ex.Message); return("Failed"); } }
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)); } }