Exemple #1
0
        public async Task <ApiResult <ServiceByKgResponseViewModel> > GetServiceByKg(int storeId, int serviceId, int userId)
        {
            ServiceByKgResponseViewModel item = null;

            try
            {
                SqlParameter StoreId = new SqlParameter("@StoreId", System.Data.SqlDbType.Int)
                {
                    Value = storeId
                };
                SqlParameter ServiceId = new SqlParameter("@ServiceId", System.Data.SqlDbType.Int)
                {
                    Value = serviceId
                };
                SqlParameter UserId = new SqlParameter("@UserId", System.Data.SqlDbType.Int)
                {
                    Value = userId
                };
                var ietms = _context.ExecuteStoreProcedure("[usp_getservicebykg]", StoreId, ServiceId, UserId);

                if (ietms.Tables[0].Rows.Count > 0)
                {
                    item = (from DataRow dr in ietms.Tables[0].Rows
                            select new ServiceByKgResponseViewModel()
                    {
                        StoreId = (dr["StoreId"] != DBNull.Value) ? Convert.ToInt32(dr["StoreId"]) : 0,
                        ServiceId = (dr["ServiceId"] != DBNull.Value) ? Convert.ToInt32(dr["ServiceId"]) : 0,
                        ServiceName = (dr["ServiceName"] != DBNull.Value) ? Convert.ToString(dr["ServiceName"]) : string.Empty,
                        pricePerKG = (dr["pricePerKG"] != DBNull.Value) ? Convert.ToDecimal(dr["pricePerKG"]) : 0,
                        QuantityInKG = (dr["QuantityInKG"] != DBNull.Value) ? Convert.ToDecimal(dr["QuantityInKG"]) : 0,
                        ServiceImageUrl = (dr["ServiceImageUrl"] != DBNull.Value) ? Convert.ToString(dr["ServiceImageUrl"]) : string.Empty,
                        CartId = (dr["CartId"] != DBNull.Value) ? Convert.ToInt32(dr["CartId"]) : 0,
                    }).FirstOrDefault();
                }
                return(item == null
                            ? new ApiResult <ServiceByKgResponseViewModel>(new ApiResultCode(ApiResultType.Error, 1, "No data in given request"))
                            : new ApiResult <ServiceByKgResponseViewModel>(new ApiResultCode(ApiResultType.Success), item));
            }
            catch (Exception ex)
            {
                ErrorTrace.Logger(LogArea.BusinessTier, ex);
                return(new ApiResult <ServiceByKgResponseViewModel>(new ApiResultCode(ApiResultType.ExceptionDuringOpration, 3, "Please contact system administrator")));
            }
        }
        public async Task <ApiResult <CartPriceDetail> > GetCartDetail(int userId, int addressId)
        {
            CartPriceDetail               priceDetail   = null;
            CartDetailResponseViewModel   model         = null;
            CartCategoryResponceViewModel categoryModel = null;
            ServiceByKgResponseViewModel  ServiceByKg   = null;

            try
            {
                SqlParameter UserId = new SqlParameter("@userId", System.Data.SqlDbType.Int)
                {
                    Value = userId
                };
                SqlParameter AddressId = new SqlParameter("@AddressId", System.Data.SqlDbType.Int)
                {
                    Value = addressId
                };
                var result = _context.ExecuteStoreProcedure("dbo.usp_GetCartDetail", UserId, AddressId);
                if (result.Tables.Count > 0 && result.Tables[0].Rows.Count > 0)
                {
                    foreach (System.Data.DataRow row in result.Tables[0].Rows)
                    {
                        priceDetail = new CartPriceDetail
                        {
                            CartCount       = (row["CartCount"] != DBNull.Value) ? Convert.ToInt32(row["CartCount"]) : 0,
                            CartPrice       = (row["CartPrice"] != DBNull.Value) ? Convert.ToDecimal(row["CartPrice"]) : 0,
                            KgCount         = (row["KgCount"] != DBNull.Value) ? Convert.ToDecimal(row["KgCount"]) : 0,
                            IsKg            = (row["IsKg"] != DBNull.Value) ? Convert.ToBoolean(row["IsKg"]) : false,
                            TaxAmount       = (row["TaxAmount"] != DBNull.Value) ? Convert.ToDecimal(row["TaxAmount"]) : 0,
                            TotalPrice      = (row["TotalAmout"] != DBNull.Value) ? Convert.ToDecimal(row["TotalAmout"]) : 0,
                            IsValidShipment = (row["IsValidShipment"] != DBNull.Value) ? Convert.ToBoolean(row["IsValidShipment"]) : false
                        };
                    }
                    foreach (System.Data.DataRow row in result.Tables[1].Rows)
                    {
                        model = new CartDetailResponseViewModel()
                        {
                            StoreId     = (row["StoreId"] != DBNull.Value) ? Convert.ToInt32(row["StoreId"]) : 0,
                            ServiceId   = (row["ServiceId"] != DBNull.Value) ? Convert.ToInt32(row["ServiceId"]) : 0,
                            ServiceName = (row["ServiceName"] != DBNull.Value) ? Convert.ToString(row["ServiceName"]) : string.Empty,
                            ServiceUrl  = (row["ServiceImage"] != DBNull.Value) ? Convert.ToString(row["ServiceImage"]) : string.Empty,
                        };
                        priceDetail.ServiceData.Add(model);
                        if (result.Tables.Count > 0 && result.Tables[2].Rows.Count > 0)
                        {
                            foreach (System.Data.DataRow catrow in result.Tables[2].Rows)
                            {
                                if (((row["ServiceId"] != DBNull.Value) ? Convert.ToInt32(row["ServiceId"]) : 0) == ((catrow["ServiceId"] != DBNull.Value) ? Convert.ToInt32(catrow["ServiceId"]) : 0))
                                {
                                    categoryModel = new CartCategoryResponceViewModel
                                    {
                                        CategoryId   = (catrow["categoryId"] != DBNull.Value) ? Convert.ToInt32(catrow["categoryId"]) : 0,
                                        CategoryName = (catrow["CategoryName"] != DBNull.Value) ? Convert.ToString(catrow["CategoryName"]) : string.Empty
                                    };
                                    model.CategoryData.Add(categoryModel);
                                    if (result.Tables.Count > 0 && result.Tables[3].Rows.Count > 0)
                                    {
                                        foreach (System.Data.DataRow itmrow in result.Tables[3].Rows)
                                        {
                                            if ((Convert.ToInt32(catrow["ServiceId"]) == Convert.ToInt32(itmrow["ServiceId"])) && Convert.ToInt32(catrow["categoryId"]) == Convert.ToInt32(itmrow["categoryId"]))
                                            {
                                                categoryModel.ItemsData.Add(new CartItemResponseDetailViewModel
                                                {
                                                    CartId     = (itmrow["CartId"] != DBNull.Value) ? Convert.ToInt32(itmrow["CartId"]) : 0,
                                                    ItemId     = (itmrow["ItemId"] != DBNull.Value) ? Convert.ToInt32(itmrow["ItemId"]) : 0,
                                                    ItemName   = (itmrow["ItemName"] != DBNull.Value) ? Convert.ToString(itmrow["ItemName"]) : string.Empty,
                                                    Quantity   = (itmrow["Quantity"] != DBNull.Value) ? Convert.ToInt32(itmrow["Quantity"]) : 0,
                                                    TotalPrice = (itmrow["totalprice"] != DBNull.Value) ? Convert.ToDecimal(itmrow["totalprice"]) : 0,
                                                    UnitPrice  = (itmrow["Price"] != DBNull.Value) ? Convert.ToDecimal(itmrow["Price"]) : 0
                                                });
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (result.Tables.Count > 0 && result.Tables[4].Rows.Count > 0)
                    {
                        foreach (System.Data.DataRow kgdata in result.Tables[4].Rows)
                        {
                            ServiceByKg = new ServiceByKgResponseViewModel()
                            {
                                StoreId         = (kgdata["StoreId"] != DBNull.Value) ? Convert.ToInt32(kgdata["StoreId"]) : 0,
                                ServiceId       = (kgdata["ServiceId"] != DBNull.Value) ? Convert.ToInt32(kgdata["ServiceId"]) : 0,
                                ServiceName     = (kgdata["ServiceName"] != DBNull.Value) ? Convert.ToString(kgdata["ServiceName"]) : string.Empty,
                                pricePerKG      = (kgdata["pricePerKG"] != DBNull.Value) ? Convert.ToDecimal(kgdata["pricePerKG"]) : 0,
                                QuantityInKG    = (kgdata["QuantityInKG"] != DBNull.Value) ? Convert.ToDecimal(kgdata["QuantityInKG"]) : 0,
                                ServiceImageUrl = (kgdata["ServiceImageUrl"] != DBNull.Value) ? Convert.ToString(kgdata["ServiceImageUrl"]) : string.Empty,
                                CartId          = (kgdata["CartId"] != DBNull.Value) ? Convert.ToInt32(kgdata["CartId"]) : 0
                            };
                            priceDetail.ServiceByKg.Add(ServiceByKg);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorTrace.Logger(LogArea.ApplicationTier, ex);
                return(new ApiResult <CartPriceDetail>(new ApiResultCode(ApiResultType.Error, 0, "No data in given request")));
            }
            return(new ApiResult <CartPriceDetail>(new ApiResultCode(ApiResultType.Success), priceDetail));
        }