Ejemplo n.º 1
0
        /// <summary>
        /// Method for updating an existing payment type - RS
        /// </summary>
        /// <param name="currentUserInstituteId"></param>
        /// <param name="updatedPaymentType"></param>
        /// <returns></returns>
        public async Task <dynamic> UpdatePaymentTypeAsync(int currentUserInstituteId, FinancePaymentType updatedPaymentType)
        {
            FinancePaymentType existingPaymentType = await _imsDbContext.FinancePaymentTypes
                                                     .FirstOrDefaultAsync(x => x.Id == updatedPaymentType.Id && x.InstituteId == currentUserInstituteId);

            if (existingPaymentType == null)
            {
                return(new { HasError = true, Message = "No payment type exists with this id" });
            }
            else if (await _imsDbContext.FinancePaymentTypes.AnyAsync(x =>
                                                                      x.Id != updatedPaymentType.Id && x.InstituteId == currentUserInstituteId &&
                                                                      x.Code.ToLowerInvariant().Equals(updatedPaymentType.Code.ToLowerInvariant())))
            {
                return(new { HasError = true, Message = "Payment Type with the same code already exists" });
            }

            existingPaymentType.Name        = updatedPaymentType.Name;
            existingPaymentType.Code        = updatedPaymentType.Code;
            existingPaymentType.Description = updatedPaymentType.Description;
            existingPaymentType.Status      = updatedPaymentType.Status;
            _imsDbContext.FinancePaymentTypes.Update(existingPaymentType);
            await _imsDbContext.SaveChangesAsync();

            return(new { HasError = false, Message = "Payment Type updated successfully" });
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> AddNewPaymentTypeAsync([FromBody] FinancePaymentType addedPaymentType)
        {
            int currentUserInstituteId = await GetUserCurrentSelectedInstituteIdAsync();

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

            return(Ok(await _financeManagementRepository.AddNewPaymentTypeAsync(currentUserInstituteId, currentUser, addedPaymentType)));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> UpdatePaymentTypeAsync([FromBody] FinancePaymentType updatedPaymentType)
        {
            int currentUserInstituteId = await GetUserCurrentSelectedInstituteIdAsync();

            return(Ok(await _financeManagementRepository.UpdatePaymentTypeAsync(currentUserInstituteId, updatedPaymentType)));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Method for adding new payment type - RS
        /// </summary>
        /// <param name="currentUserInstituteId"></param>
        /// <param name="currentUser"></param>
        /// <param name="addedPaymentType"></param>
        /// <returns></returns>
        public async Task <dynamic> AddNewPaymentTypeAsync(int currentUserInstituteId, ApplicationUser currentUser, FinancePaymentType addedPaymentType)
        {
            if (await _imsDbContext.FinancePaymentTypes.AnyAsync(x => x.InstituteId == currentUserInstituteId && x.Code.ToLowerInvariant().Equals(addedPaymentType.Code.ToLowerInvariant())))
            {
                return(new { HasError = true, Message = "Payment Type with the same code already exists" });
            }

            addedPaymentType.InstituteId = currentUserInstituteId;
            addedPaymentType.CreatedOn   = DateTime.UtcNow;
            addedPaymentType.CreatedBy   = currentUser.Id;
            addedPaymentType.Status      = true;
            _imsDbContext.FinancePaymentTypes.Add(addedPaymentType);
            await _imsDbContext.SaveChangesAsync();

            return(new { HasError = false, Message = "Payment Type added successfully" });
        }