Example #1
0
        public async Task <SharedLookUpResponse> UpdateComponentAsync(UpdateTaxType updateComponentAc, int instituteId)
        {
            var componentGroups = await iMSDbContext.TaxTypes.Where(x => x.InstituteId == instituteId && x.Id != updateComponentAc.Id).ToListAsync();

            var isDuplicated = componentGroups.Any(x => x.Code.ToLowerInvariant() == updateComponentAc.Code.ToLowerInvariant());

            if (isDuplicated)
            {
                return new SharedLookUpResponse()
                       {
                           HasError = true, ErrorType = SharedLookUpResponseType.Code, Message = "Duplicate Code of Tax Type, please use unique code"
                       }
            }
            ;
            else
            {
                var componentGroup = await iMSDbContext.TaxTypes.FirstAsync(x => x.Id == updateComponentAc.Id);

                componentGroup.Name   = updateComponentAc.Name;
                componentGroup.Code   = updateComponentAc.Code;
                componentGroup.Type   = updateComponentAc.Type;
                componentGroup.Value  = updateComponentAc.Value;
                componentGroup.Status = updateComponentAc.Status;
                iMSDbContext.TaxTypes.Update(componentGroup);
                await iMSDbContext.SaveChangesAsync();

                return(new SharedLookUpResponse()
                {
                    HasError = false, Message = "Tax Type updated successfully"
                });
            }
        }
Example #2
0
        public async Task <IActionResult> UpdateGroupAsync([FromBody] UpdateTaxType updateComponentGroupAc)
        {
            if (string.IsNullOrEmpty(updateComponentGroupAc.Name.Trim()))
            {
                return(Ok(new SharedLookUpResponse()
                {
                    HasError = true,
                    ErrorType = SharedLookUpResponseType.Name,
                    Message = "Tax Type name can't be null or empty"
                }));
            }
            else if (string.IsNullOrEmpty(updateComponentGroupAc.Code.Trim()))
            {
                return(Ok(new SharedLookUpResponse()
                {
                    HasError = true,
                    ErrorType = SharedLookUpResponseType.Name,
                    Message = "Tax Type code can't be null or empty"
                }));
            }
            else
            {
                var instituteId = await GetUserCurrentSelectedInstituteIdAsync();

                if (await iMSDbContext.TaxTypes.AnyAsync(x => x.Id == updateComponentGroupAc.Id && x.InstituteId == instituteId))
                {
                    return(Ok(await taxTypeManagementRepository.UpdateComponentAsync(updateComponentGroupAc, instituteId)));
                }
                else
                {
                    return(Ok(new SharedLookUpResponse()
                    {
                        HasError = true, ErrorType = SharedLookUpResponseType.Code, Message = "Tax Type not found"
                    }));
                }
            }
        }