示例#1
0
        public bool AddSales(Admin admin, Sales sales, List<SalesInfo> salesInfo, bool stock)
        {
            if (sales == null || salesInfo == null) throw new Exception(ErrorConstants.REQUIRED_FIELD_EMPTY);

            if (admin == null || admin.type != (int)BillingEnums.USER_TYPE.ADMIN) throw new Exception(ErrorConstants.NO_PREVILAGE);

            try
            {
                
                var elasticClient = GetElasticClient();

                var salesResponse = elasticClient.Index<Sales>(sales, i => i
                .Index(ElasticMappingConstants.INDEX_NAME)
                .Type(ElasticMappingConstants.TYPE_SALES)
                );

                var insertDescriptor = new BulkDescriptor();

                foreach (var item in salesInfo)
                {
                    item.salesid = sales.salesid;
                    
                    insertDescriptor.Index<SalesInfo>(i => i
                    .Index(ElasticMappingConstants.INDEX_NAME)
                    .Type(ElasticMappingConstants.TYPE_SALES_INFO)
                    .Document(item)
                    );
                }


                var bulkResponse = elasticClient.Bulk(insertDescriptor);

                return salesResponse.RequestInformation.Success && bulkResponse.RequestInformation.Success;

            }
            catch (Exception e)
            {

                throw e;
            }

        }
示例#2
0
        public JsonResult AddSales()
        {
            var billNo = Request.Params.Get(AppConstants.BILL_NO);
            var dateTime = Request.Params.Get(AppConstants.DATE_TIME);
            var salesInfo = Request.Params.Get(AppConstants.SALES_INFO);
            var tax = Request.Params.Get(AppConstants.TAX);
            var discount = Request.Params.Get(AppConstants.DISCOUNT);
            var maintainStock = Request.Params.Get(AppConstants.MAINTAIN_STOCK);

            float taxFloat, discountFloat = 0;
            DateTime date;
            bool maintainStockBool;
            var response = new ServiceResponse();
            var admin = CookieHelper.GetLoggedInAdmin(HttpContext);
            if(admin == null)
            {
                response.result = ErrorConstants.ADMIN_NOT_LOGGED_IN;
                return Json(response);
            }
            if(String.IsNullOrWhiteSpace(billNo) || String.IsNullOrWhiteSpace(dateTime) || String.IsNullOrWhiteSpace(salesInfo) || String.IsNullOrWhiteSpace(tax))
            {
                response.result = ErrorConstants.REQUIRED_FIELD_EMPTY;
                return Json(response);
            }
            if(!DateTime.TryParse(dateTime, out date))
            {
                response.result = ErrorConstants.INVALID_DATA;
                return Json(response);
            }
            if(!float.TryParse(tax, out taxFloat))
            {
                response.result = ErrorConstants.INVALID_DATA;
                return Json(response);
            }
            if(!String.IsNullOrWhiteSpace(discount) && !float.TryParse(discount, out discountFloat))
            {
                response.result = ErrorConstants.INVALID_DATA;
                return Json(response);
            }
            maintainStockBool = bool.TryParse(maintainStock, out maintainStockBool) ? maintainStockBool : false;

            var sales = new List<SalesInfo>();

            try
            {
                var bill = new Sales() {
                    salesid = Guid.NewGuid(),
                    billno = billNo,
                    date = date,
                    tax = taxFloat,
                    discount = discountFloat,
                    status = (short) BillingEnums.STATUS.CLEARED,
                    created_at = DateTime.UtcNow
                    
                };
                sales = JsonConvert.DeserializeObject<List<SalesInfo>>(salesInfo);
            }
            catch (Exception e)
            {

                Console.Error.WriteLine(e.GetBaseException().Message);
                response.result = e.GetBaseException().Message;
            }

            return Json(response);
        }