public async Task <SharedLookUpResponse> AddComponentAsync(AddComponentAc addComponent, int instituteId)
        {
            if (!await iMSDbContext.PayrollComponents.AnyAsync(x => x.InstituteId == instituteId && x.Name.ToLowerInvariant() == addComponent.Name.ToLowerInvariant()))
            {
                var component = new PayrollComponent()
                {
                    CreatedOn   = DateTime.UtcNow,
                    InstituteId = instituteId,
                    Name        = addComponent.Name,
                    ShortName   = addComponent.ShortName,
                    SequenceNo  = addComponent.SequenceNo,
                    GroupId     = addComponent.GroupId,
                    IsPayslip   = addComponent.IsPayslip,
                    IsBasic     = addComponent.IsBasic,
                    Others      = addComponent.Others,
                    Description = addComponent.Description,
                    Status      = addComponent.Status
                };
                iMSDbContext.PayrollComponents.Add(component);
                await iMSDbContext.SaveChangesAsync();

                return(new SharedLookUpResponse()
                {
                    HasError = false, Message = "Component Group added successfully"
                });
            }
            else
            {
                return(new SharedLookUpResponse()
                {
                    HasError = true, ErrorType = SharedLookUpResponseType.Code, Message = "Component with same Name is already existed"
                });
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> Update([FromBody] PayrollComponent payrollComponent)
        {
            int result = 0;

            try
            {
                context.Update(payrollComponent);
                result = await context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                logger.LogError(ex.ToString());
            }
            return(Ok(result));
        }