Ejemplo n.º 1
0
        public async Task <CertificateViewModel <SaveCertificateResource> > UpdateOrderIndexCertificate(SwapOrderIndexRequestModel swapId)
        {
            model.AppResult.Result = false;
            var tempCurrentCertificateInfo = await _certificateRepository.FindAsync(swapId.CurrentId);

            var tempTurnedCertificateInfo = await _certificateRepository.FindAsync(swapId.TurnedId);

            if (tempCurrentCertificateInfo is null || tempTurnedCertificateInfo is null)
            {
                model.AppResult.Message = Constant.SWAP_ERROR;
                return(model);
            }

            // Set who edited?
            tempCurrentCertificateInfo.UpdatedBy = Helpers.HttpContext.CurrentUser;
            tempCurrentCertificateInfo.UpdatedAt = DateTime.Now;

            tempTurnedCertificateInfo.UpdatedBy = Helpers.HttpContext.CurrentUser;
            tempTurnedCertificateInfo.UpdatedAt = DateTime.Now;

            // Swap OrderIndex
            int tempOrderIndex = 0;

            tempOrderIndex = tempCurrentCertificateInfo.OrderIndex;
            tempCurrentCertificateInfo.OrderIndex = tempTurnedCertificateInfo.OrderIndex;
            tempTurnedCertificateInfo.OrderIndex  = tempOrderIndex;
            // Execute swap
            var isSuccess = await _certificateRepository.SwapOrderIndexAsync(tempCurrentCertificateInfo, tempTurnedCertificateInfo);

            if (isSuccess)
            {
                model.AppResult.Result  = true;
                model.AppResult.Message = Constant.SWAP_SUCCESS;
                return(model);
            }
            model.AppResult.Message = "Taylor Swift";
            return(model);
        }