/// <summary>Add roles to policy list based on access level</summary>
        public void CreatePolicy()
        {
            var roles = MH.GetListOfObjects(null, null, null, null, null, null, "RolesDB", "Roles").Result;

            if (roles != null)
            {
                foreach (var role in roles)
                {
                    var data = BsonSerializer.Deserialize <Roles>(role).LevelOfAccess;
                    foreach (var access in data)
                    {
                        if (access == "Level1Access")
                        {
                            level1RoleList.Add((BsonSerializer.Deserialize <Roles>(role).RoleName));
                        }
                        else if (access == "Level2Access")
                        {
                            level2RoleList.Add((BsonSerializer.Deserialize <Roles>(role).RoleName));
                        }
                        else if (access == "Level3Access")
                        {
                            level3RoleList.Add((BsonSerializer.Deserialize <Roles>(role).RoleName));
                        }
                    }
                }
            }
        }
 public ActionResult GetOrderById(int orderid)
 {
     try
     {
         var checkData = MH.CheckForDatas("OrderId", orderid, null, null, "OrderDB", "OrderInfo");
         if (checkData != null)
         {
             return(Ok(new ResponseData
             {
                 Code = "200",
                 Message = "Success",
                 Data = BsonSerializer.Deserialize <OrderInfo>(checkData)
             }));
         }
         else
         {
             return(BadRequest(new ResponseData
             {
                 Code = "404",
                 Message = "No orders found",
                 Data = null
             }));
         }
     }
     catch (Exception ex)
     {
         LoggerDataAccess.CreateLog("OrderController", "GetOrdersOfUser", ex.Message);
         return(BadRequest(new ResponseData
         {
             Code = "400",
             Message = "Failed",
             Data = ex.Message
         }));
     }
 }
Exemple #3
0
        public void Helper_Mongo_GetMongoClient()
        {
            //Arrange

            //Act
            var result = MOH.GetClient() as MongoClient;

            //Assert
            Assert.IsNotNull(result);
        }
Exemple #4
0
        public async Task <ActionResult> Subscribe(string emailid)
        {
            try
            {
                if (emailid != null)
                {
                    var checkUser = MH.CheckForDatas("Email", emailid, null, null, "SubscribeDB", "SubscribedUsers");
                    if (checkUser == null)
                    {
                        await _db.GetCollection <Subscribe>("SubscribedUsers").InsertOneAsync(new Subscribe {
                            Email = emailid
                        });

                        var sendEmail = EmailHelper.SendEmail_NewsLetterService(emailid);
                        return(Ok(new ResponseData
                        {
                            Code = "200",
                            Message = "Subscribed Succesfully",
                            Data = null
                        }));
                    }
                    else
                    {
                        return(BadRequest(new ResponseData
                        {
                            Code = "401",
                            Message = "User Already Subscribed",
                            Data = null
                        }));
                    }
                }
                else
                {
                    return(BadRequest(new ResponseData
                    {
                        Code = "402",
                        Message = "EmailId connot be empty",
                        Data = null
                    }));
                }
            }
            catch (Exception ex)
            {
                LoggerDataAccess.CreateLog("AdminContoller", "Subscribe", ex.Message);
                return(BadRequest(new ResponseData
                {
                    Code = "400",
                    Message = "Failed",
                    Data = ex.Message
                }));
            }
        }
        public ActionResult Unsubscribe(string username)
        {
            try
            {
                if (username != null)
                {
                    var user = MH.CheckForDatas("UserName", username, null, null, "SubscribeDB", "SubscribedUsers");
                    if (user != null)
                    {
                        var filter = Builders <BsonDocument> .Filter.Eq("UserName", username);

                        MH.DeleteSingleObject(filter, "SubscribeDB", "SubscribedUsers");
                        return(Ok(new ResponseData
                        {
                            Code = "200",
                            Message = "Unsubscribed Succesfully",
                            Data = null
                        }));
                    }
                    else
                    {
                        return(BadRequest(new ResponseData
                        {
                            Code = "404",
                            Message = "No user found",
                            Data = null
                        }));
                    }
                }
                else
                {
                    return(BadRequest(new ResponseData
                    {
                        Code = "402",
                        Message = "UserName connot be empty",
                        Data = null
                    }));
                }
            }
            catch (Exception ex)
            {
                LoggerDataAccess.CreateLog("AdminContoller", "Unsubscribe", "Unsubscribe", ex.Message);
                return(BadRequest(new ResponseData
                {
                    Code = "400",
                    Message = "Failed",
                    Data = ex.Message
                }));
            }
        }
        public async Task <ActionResult> Subscribe(string username)
        {
            try
            {
                if (username != null)
                {
                    var user = MH.CheckForDatas("UserName", username, null, null, "SubscribeDB", "SubscribedUsers");
                    if (user == null)
                    {
                        var collection = _db.GetCollection <Subscribe>("SubscribedUsers");
                        await collection.InsertOneAsync(new Subscribe { UserName = username });

                        return(Ok(new ResponseData
                        {
                            Code = "200",
                            Message = "Subscribed Succesfully",
                            Data = null
                        }));
                    }
                    else
                    {
                        return(BadRequest(new ResponseData
                        {
                            Code = "401",
                            Message = "User Already Subscribed",
                            Data = null
                        }));
                    }
                }
                else
                {
                    return(BadRequest(new ResponseData
                    {
                        Code = "402",
                        Message = "UserName connot be empty",
                        Data = null
                    }));
                }
            }
            catch (Exception ex)
            {
                LoggerDataAccess.CreateLog("AdminContoller", "Subscribe", "Subscribe", ex.Message);
                return(BadRequest(new ResponseData
                {
                    Code = "400",
                    Message = "Failed",
                    Data = ex.Message
                }));
            }
        }
Exemple #7
0
        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,);
        }
Exemple #8
0
        public async Task <ActionResult> InsertRole([FromBody] Roles data)
        {
            try
            {
                if (MH.CheckForDatas("RoleName", data.RoleName, null, null, "RolesDB", "Roles") != null)
                {
                    return(BadRequest(new ResponseData
                    {
                        Code = "401",
                        Message = "Another role with same name is found",
                        Data = null
                    }));
                }
                else if (MH.CheckForDatas("RoleID", data.RoleID, null, null, "RolesDB", "Roles") != null)
                {
                    return(BadRequest(new ResponseData
                    {
                        Code = "402",
                        Message = "Another role with same role id is found",
                        Data = null
                    }));
                }
                else
                {
                    await MH._client.GetDatabase("RolesDB").GetCollection <Roles>("Roles").InsertOneAsync(data);

                    return(Ok(new ResponseData
                    {
                        Code = "200",
                        Message = "Role inserted successfully",
                        Data = null
                    }));
                }
            }
            catch (Exception ex)
            {
                LoggerDataAccess.CreateLog("AdminContoller", "InsertRole", ex.Message);
                return(BadRequest(new ResponseData
                {
                    Code = "400",
                    Message = "Failed",
                    Data = ex.Message
                }));
            }
        }
Exemple #9
0
 public ActionResult GetRolesByLevelOfAccess(string levelofaccess)
 {
     try
     {
         var getRoles = MH.GetListOfObjects(null, null, null, null, null, null, "RolesDB", "Roles").Result;
         if (getRoles != null)
         {
             List <Roles> rolesList = new List <Roles>();
             foreach (var role in getRoles)
             {
                 var    roleInfo    = BsonSerializer.Deserialize <Roles>(role);
                 string accessLevel = "Level" + levelofaccess + "Access";
                 if (roleInfo.LevelOfAccess.Contains(accessLevel))
                 {
                     rolesList.Add(roleInfo);
                 }
             }
             return(Ok(new ResponseData
             {
                 Code = "200",
                 Message = "Success",
                 Data = rolesList
             }));
         }
         else
         {
             return(BadRequest(new ResponseData
             {
                 Code = "404",
                 Message = "No roles found",
                 Data = null
             }));
         }
     }
     catch (Exception ex)
     {
         LoggerDataAccess.CreateLog("AdminContoller", "GetRolesByLevelOfAccess", ex.Message);
         return(BadRequest(new ResponseData
         {
             Code = "400",
             Message = "Failed",
             Data = ex.Message
         }));
     }
 }
 public ActionResult GetOrdersOfUser(string username)
 {
     try
     {
         var orderList = MH.GetListOfObjects("UserName", username, null, null, null, null, "OrderDB", "OrderInfo").Result;
         if (orderList != null)
         {
             List <OrderInfo> orders = new List <OrderInfo>();
             foreach (var order in orderList)
             {
                 orders.Add(BsonSerializer.Deserialize <OrderInfo>(order));
             }
             return(Ok(new ResponseData
             {
                 Code = "200",
                 Message = "Success",
                 Data = orders
             }));
         }
         else
         {
             return(BadRequest(new ResponseData
             {
                 Code = "404",
                 Message = "No orders found",
                 Data = null
             }));
         }
     }
     catch (Exception ex)
     {
         LoggerDataAccess.CreateLog("OrderController", "GetOrdersOfUser", ex.Message);
         return(BadRequest(new ResponseData
         {
             Code = "400",
             Message = "Failed",
             Data = ex.Message
         }));
     }
 }
Exemple #11
0
        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));
            }
        }
Exemple #12
0
 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
         }));
     }
 }
Exemple #13
0
 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 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
         }));
     }
 }
Exemple #18
0
        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));
            }
        }
Exemple #19
0
        /// <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");
            }
        }
Exemple #20
0
 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
         }));
     }
 }