Пример #1
0
        /// <summary>
        /// Method for updating an existing finance payment - RS
        /// </summary>
        /// <param name="currentUserInstituteId"></param>
        /// <param name="updatedFinancePayment"></param>
        /// <returns></returns>
        public async Task <dynamic> UpdateFinancePaymentAsync(int currentUserInstituteId, FinancePayment updatedFinancePayment)
        {
            FinancePayment existingFinancePayment = await _imsDbContext.FinancePayments
                                                    .FirstOrDefaultAsync(x => x.Id == updatedFinancePayment.Id && x.InstituteId == currentUserInstituteId);

            if (existingFinancePayment == null)
            {
                return(new { Message = "No finance payment exists with this id", HasError = true });
            }
            else if (await _imsDbContext.FinancePayments.AnyAsync(x => x.InstituteId == currentUserInstituteId &&
                                                                  x.Id != updatedFinancePayment.Id &&
                                                                  x.Code.ToLowerInvariant().Equals(updatedFinancePayment.Code.ToLowerInvariant())))
            {
                return(new { Message = "Finance payment already exist with this code", HasError = true });
            }

            existingFinancePayment.Amount           = updatedFinancePayment.Amount;
            existingFinancePayment.Code             = updatedFinancePayment.Code;
            existingFinancePayment.PaidToId         = updatedFinancePayment.PaidToId;
            existingFinancePayment.PaymentById      = updatedFinancePayment.PaymentById;
            existingFinancePayment.PaymentDate      = updatedFinancePayment.PaymentDate;
            existingFinancePayment.PaymentReference = updatedFinancePayment.PaymentReference;
            existingFinancePayment.PaymentTypeId    = updatedFinancePayment.PaymentTypeId;
            existingFinancePayment.ReferenceCode    = updatedFinancePayment.ReferenceCode;
            existingFinancePayment.ReferenceDate    = updatedFinancePayment.ReferenceDate;
            _imsDbContext.FinancePayments.Update(existingFinancePayment);
            await _imsDbContext.SaveChangesAsync();

            return(new { Message = "Finance payment updated successfully", HasError = false });
        }
Пример #2
0
        public async Task <IActionResult> AddNewFinancePaymentAsync([FromBody] FinancePayment addedFinancePayment)
        {
            int currentUserInstituteId = await GetUserCurrentSelectedInstituteIdAsync();

            ApplicationUser currentUser = await _userManager.FindByNameAsync(User.Identity.Name);

            return(Ok(await _financeManagementRepository.AddNewFinancePaymentAsync(currentUserInstituteId, currentUser, addedFinancePayment)));
        }
Пример #3
0
        public async Task <IActionResult> UpdateFinancePaymentAsync([FromBody] FinancePayment updatedFinancePayment)
        {
            int currentUserInstituteId = await GetUserCurrentSelectedInstituteIdAsync();

            return(Ok(await _financeManagementRepository.UpdateFinancePaymentAsync(currentUserInstituteId, updatedFinancePayment)));
        }
Пример #4
0
        /// <summary>
        /// Method for adding new finance payment - RS
        /// </summary>
        /// <param name="currentUserInstituteId"></param>
        /// <param name="currentUser"></param>
        /// <param name="addedFinancePayment"></param>
        /// <returns></returns>
        public async Task <dynamic> AddNewFinancePaymentAsync(int currentUserInstituteId, ApplicationUser currentUser, FinancePayment addedFinancePayment)
        {
            if (await _imsDbContext.FinancePayments.AnyAsync(x => x.InstituteId == currentUserInstituteId && x.Code.ToLowerInvariant().Equals(addedFinancePayment.Code.ToLowerInvariant())))
            {
                return(new { Message = "Finance payment already exist with this code", HasError = true });
            }

            addedFinancePayment.CreatedBy   = currentUser.Id;
            addedFinancePayment.CreatedOn   = DateTime.UtcNow;
            addedFinancePayment.InstituteId = currentUserInstituteId;
            _imsDbContext.Add(addedFinancePayment);
            await _imsDbContext.SaveChangesAsync();

            return(new { Message = "Finance payment added successfully", HasError = false });
        }