Exemple #1
0
        /// <summary>
        /// Raise Claim
        /// </summary>
        /// <param name="storeClaimMaster"></param>
        /// <param name="finalAttchment"></param>
        /// <returns></returns>
        public int RaiseClaim(StoreClaimMaster storeClaimMaster, string finalAttchment)
        {
            int ClaimID = 0;

            try
            {
                conn.Open();
                MySqlCommand cmd = new MySqlCommand("SP_InsertRaiseClaim", conn);
                cmd.Parameters.AddWithValue("@Tenant_ID", storeClaimMaster.TenantID);
                cmd.Parameters.AddWithValue("@Created_By", storeClaimMaster.CreatedBy);
                cmd.Parameters.AddWithValue("@fileName", string.IsNullOrEmpty(finalAttchment) ? "" : finalAttchment);
                cmd.Parameters.AddWithValue("@Brand_ID", storeClaimMaster.BrandID);
                cmd.Parameters.AddWithValue("@Category_ID", storeClaimMaster.CategoryID);
                cmd.Parameters.AddWithValue("@SubCategory_ID", storeClaimMaster.SubCategoryID);
                cmd.Parameters.AddWithValue("@IssueType_ID", storeClaimMaster.IssueTypeID);
                cmd.Parameters.AddWithValue("@Order_IDs", string.IsNullOrEmpty(storeClaimMaster.OrderItemID) ? "" : storeClaimMaster.OrderItemID);
                cmd.Parameters.AddWithValue("@Claim_Percent", storeClaimMaster.ClaimPercent);
                cmd.Parameters.AddWithValue("@Customer_ID", storeClaimMaster.CustomerID);
                cmd.Parameters.AddWithValue("@Ticket_ID", storeClaimMaster.TicketID);
                cmd.Parameters.AddWithValue("@Ticketing_TaskID", storeClaimMaster.TaskID);
                cmd.CommandType = CommandType.StoredProcedure;
                ClaimID         = Convert.ToInt32(cmd.ExecuteScalar());
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
            }
            return(ClaimID);
        }
 /// <summary>
 /// InsertRaiseClaim
 /// </summary>
 /// <param name="storeClaim"></param>
 /// <param name="storeClaimMaster"></param>
 /// <param name="finalAttchment"></param>
 /// <returns></returns>
 public int InsertRaiseClaim(IStoreClaim storeClaim, StoreClaimMaster storeClaimMaster, string finalAttchment)
 {
     _ClaimRepository = storeClaim;
     return(_ClaimRepository.RaiseClaim(storeClaimMaster, finalAttchment));
 }
        public ResponseModel RaiseClaim(IFormFile File)
        {
            StoreClaimMaster storeClaimMaster = new StoreClaimMaster();
            OrderMaster      orderDetails     = new OrderMaster();
            List <OrderItem> OrderItemDetails = new List <OrderItem>();
            var    files          = Request.Form.Files;
            string timeStamp      = DateTime.Now.ToString("ddmmyyyyhhssfff");
            string fileName       = "";
            string finalAttchment = "";
            string ImagePath      = string.Empty;

            if (files.Count > 0)
            {
                for (int i = 0; i < files.Count; i++)
                {
                    fileName += files[i].FileName.Replace(".", timeStamp + ".") + ",";
                }
                finalAttchment = fileName.TrimEnd(',');
            }
            var Keys = Request.Form;

            storeClaimMaster = JsonConvert.DeserializeObject <StoreClaimMaster>(Keys["storeClaimMaster"]);
            // get order details from form
            orderDetails     = JsonConvert.DeserializeObject <OrderMaster>(Keys["orderDetails"]);
            OrderItemDetails = JsonConvert.DeserializeObject <List <OrderItem> >(Keys["orderItemDetails"]);

            //var exePath = Path.GetDirectoryName(System.Reflection
            //        .Assembly.GetExecutingAssembly().CodeBase);
            //Regex appPathMatcher = new Regex(@"(?<!fil)[A-Za-z]:\\+[\S\s]*?(?=\\+bin)");
            //var appRoot = appPathMatcher.Match(exePath).Value;
            // string folderpath = rootPath + _ClaimProductImage;
            string Folderpath = Directory.GetCurrentDirectory();

            string[] filesName = finalAttchment.Split(",");


            ImagePath = Path.Combine(Folderpath, _ClaimProductImage);

            if (!Directory.Exists(ImagePath))
            {
                Directory.CreateDirectory(ImagePath);
            }

            ResponseModel objResponseModel = new ResponseModel();
            int           statusCode       = 0;
            string        statusMessage    = "";

            try
            {
                string       token        = Convert.ToString(Request.Headers["X-Authorized-Token"]);
                Authenticate authenticate = new Authenticate();
                authenticate = SecurityService.GetAuthenticateDataFromToken(_radisCacheServerAddress, SecurityService.DecryptStringAES(token));

                #region check orderdetails and item details

                if (orderDetails != null)
                {
                    if (orderDetails.OrderMasterID.Equals(0))
                    {
                        string      OrderNumber    = string.Empty;
                        string      OrderItemsIds  = string.Empty;
                        OrderMaster objorderMaster = null;

                        OrderCaller ordercaller = new OrderCaller();
                        //call insert order
                        orderDetails.CreatedBy = authenticate.UserMasterID;
                        OrderNumber            = ordercaller.addOrder(new OrderService(_connectionSting), orderDetails, authenticate.TenantId);
                        if (!string.IsNullOrEmpty(OrderNumber))
                        {
                            objorderMaster = ordercaller.getOrderDetailsByNumber(new OrderService(_connectionSting), OrderNumber, authenticate.TenantId);


                            if (objorderMaster != null)
                            {
                                if (OrderItemDetails != null)
                                {
                                    foreach (var item in OrderItemDetails)
                                    {
                                        item.OrderMasterID = objorderMaster.OrderMasterID;
                                        item.InvoiceDate   = orderDetails.InvoiceDate;
                                    }

                                    OrderItemsIds = ordercaller.AddOrderItem(new OrderService(_connectionSting), OrderItemDetails, authenticate.TenantId, authenticate.UserMasterID);
                                }
                                else
                                {
                                    OrderItemsIds = Convert.ToString(objorderMaster.OrderMasterID) + "|0|1";
                                    //OrderItemsIds = Convert.ToString(objorderMaster.OrderMasterID) + "|1";
                                }
                            }

                            storeClaimMaster.OrderMasterID = objorderMaster.OrderMasterID;
                            storeClaimMaster.OrderItemID   = OrderItemsIds;
                        }
                    }
                }
                #endregion

                StoreClaimCaller storeClaimCaller = new StoreClaimCaller();
                storeClaimMaster.TenantID  = authenticate.TenantId;
                storeClaimMaster.CreatedBy = authenticate.UserMasterID;
                int result = storeClaimCaller.InsertRaiseClaim(new StoreClaimService(_connectionSting), storeClaimMaster, finalAttchment);
                if (result > 0)
                {
                    if (files.Count > 0)
                    {
                        //string[] filesName = finalAttchment.Split(",");
                        for (int i = 0; i < files.Count; i++)
                        {
                            try
                            {
                                using (var ms = new MemoryStream())
                                {
                                    files[i].CopyTo(ms);
                                    var          fileBytes = ms.ToArray();
                                    MemoryStream msfile    = new MemoryStream(fileBytes);
                                    FileStream   docFile   = new FileStream(Path.Combine(ImagePath, filesName[i]), FileMode.Create, FileAccess.Write);
                                    msfile.WriteTo(docFile);
                                    docFile.Close();
                                    ms.Close();
                                    msfile.Close();
                                    string s = Convert.ToBase64String(fileBytes);
                                    byte[] a = Convert.FromBase64String(s);
                                    // act on the Base64 data
                                }
                                //using (var ms = new MemoryStream())
                                //{
                                //    files[i].CopyTo(ms);
                                //    var fileBytes = ms.ToArray();
                                //    MemoryStream msfile = new MemoryStream(fileBytes);
                                //    FileStream docFile = new FileStream(folderpath + "/" + filesName[i], FileMode.Create, FileAccess.Write);
                                //    msfile.WriteTo(docFile);
                                //    docFile.Close();
                                //    ms.Close();
                                //    msfile.Close();
                                //    string s = Convert.ToBase64String(fileBytes);
                                //    byte[] a = Convert.FromBase64String(s);
                                //    // act on the Base64 data

                                //}
                            }
                            catch (Exception)
                            {
                                throw;
                            }
                        }
                    }
                }
                statusCode =
                    result == 0 ?
                    (int)EnumMaster.StatusCode.RecordNotFound : (int)EnumMaster.StatusCode.Success;
                statusMessage                 = CommonFunction.GetEnumDescription((EnumMaster.StatusCode)statusCode);
                objResponseModel.Status       = true;
                objResponseModel.StatusCode   = statusCode;
                objResponseModel.Message      = statusMessage;
                objResponseModel.ResponseData = result;
            }
            catch (Exception)
            {
                throw;
            }
            return(objResponseModel);
        }