Example #1
0
        public IActionResult Post([FromBody] KkmRequest request)
        {
            try
            {
                Log.Information("ZReport|Post");
                Log.Information($"Z-Отчет: {request.Token}");

                var user            = _userManager.Users.FirstOrDefault(u => u.UserToken == request.Token);
                var kkm             = _applicationContext.Kkms.FirstOrDefault(k => k.UserId == user.Id);
                var shift           = _applicationContext.Shifts.Last(s => s.KkmId == kkm.Id);
                var operations      = _applicationContext.Operations.Where(o => o.ShiftId == shift.Id);
                var shiftOperations = ZxReportService.GetShiftOperations(operations, shift);
                ZxReportService.AddShiftProps(shift, operations);
                ZxReportService.CloseShift(true, shift);
                var merch = _userManager.Users.FirstOrDefault(u => u.Id == kkm.UserId);
                var closeShiftOfdResponse = OfdRequest(kkm, merch, shift.Number);
                if (kkm == null)
                {
                    return(Json(_errorHelper.GetErrorRequest(3)));
                }
                kkm.OfdToken = closeShiftOfdResponse.Result.Token;
                kkm.ReqNum  += 1;
                var response = new XReportKkmResponse(shiftOperations, operations, user, kkm, shift);
                _applicationContext.ShiftOperations.AddRangeAsync(shiftOperations);
                _applicationContext.SaveChangesAsync();
                return(Ok(JsonConvert.SerializeObject(response)));
            }
            catch (Exception e)
            {
                Log.Error(e.Message);
                return(Json(e.Message));
            }
        }
Example #2
0
        public async Task <IActionResult> Post([FromBody] KkmRequest request)
        {
            try
            {
                var   user  = _userManager.Users.FirstOrDefault(u => u.UserToken == request.Token);
                var   kkm   = _applicationContext.Kkms.FirstOrDefault(k => k.Id == user.KkmId);
                var   merch = _userManager.Users.FirstOrDefault(u => user.OwnerId == u.Id);
                Shift shift;
                try
                {
                    shift = _applicationContext.Shifts.Last(s => s.KkmId == kkm.Id && s.CloseDate == DateTime.MinValue);
                }
                catch (Exception)
                {
                    shift = await GetShift(user, kkm);
                }
                var operations      = _applicationContext.Operations.Where(o => o.ShiftId == shift.Id);
                var shiftOperations = ZxReportService.GetShiftOperations(operations, shift);
                ZxReportService.AddShiftProps(shift, operations);
                var response = new XReportKkmResponse(shiftOperations, operations, merch, kkm, shift);
                if (kkm == null)
                {
                    return(Json(_errorHelper.GetErrorRequest(3)));
                }
                kkm.ReqNum += 1;
                await _applicationContext.ShiftOperations.AddRangeAsync(shiftOperations);

                await _applicationContext.SaveChangesAsync();

                var xReportOfdRequest = new OfdXReport();
                xReportOfdRequest.Request(kkm, merch);

                return(Ok(JsonConvert.SerializeObject(response)));
            }
            catch (Exception e)
            {
                return(Json(e.Message));
            }
        }