Exemplo n.º 1
0
        public async Task <bool> UpdateAsync(GuarantorDTO user)
        {
            try
            {
                GuarantorModel guarantor = new GuarantorModel()
                {
                    Address      = user.Address,
                    Email        = user.Email,
                    Gender       = user.Gender,
                    PhoneNumber1 = user.PhoneNumber1,
                    PhoneNumber2 = user.PhoneNumber2,
                    State        = user.State,
                    Surname      = user.Surname,
                    LastName     = user.LastName,
                };


                _context.Guarantor.Attach(guarantor);

                await _context.SaveChangesAsync();

                _context.Dispose();

                return(Task.CompletedTask.IsCompleted);
            }
            catch (Exception ex) { }

            return(Task.CompletedTask.IsCanceled);
        }
Exemplo n.º 2
0
        public IEnumerable <GuarantorModel> MapToGuarantorModel(IEnumerable <Guarantor> guarantorsList)
        {
            IList <GuarantorModel> returnedGuarantors = new List <GuarantorModel>();

            foreach (var guarantor in guarantorsList)
            {
                GuarantorModel retGuarantor = MapToGuarantorModel(guarantor);
                returnedGuarantors.Add(retGuarantor);
            }
            return(returnedGuarantors);
        }
Exemplo n.º 3
0
        public GuarantorModel MapToGuarantorModel(Guarantor guarantor)
        {
            GuarantorModel retGuarantor = null;

            try
            {
                retGuarantor = _mapper.Map <GuarantorModel>(guarantor);
                retGuarantor.FamiliesCount = -1;
                retGuarantor.OrphansCount  = -1;
            }
            catch
            {
                retGuarantor = null;
            }
            return(retGuarantor);
        }
Exemplo n.º 4
0
        public async Task <string> CreateUserAsync(CreateUserDTO model)
        {
            var user = new UserProfileModel
            {
                UserName    = model.Email,
                Email       = model.Email,
                FirstName   = model.FirstName,
                LastName    = model.LastName,
                PhoneNumber = model.PhoneNumber,
                IsActive    = true,
                Surname     = model.Surname,
                Address     = model.Address,
            };

            if (!await _roleManager.RoleExistsAsync(model.UserType))
            {
                return("Invalid role");
            }

            var result = await _userManager.CreateAsync(user, model.Password);

            if (result.Succeeded)
            {
                if (model.UserType.ToString().Equals(ApplicationRoles.GUARANTOR))
                {
                    using (var context = _context)
                    {
                        GuarantorModel guarantor = new GuarantorModel
                        {
                            Address   = model.Address,
                            Email     = model.Email,
                            FirstName = model.FirstName,
                            Gender    = model.Gender,

                            LastName     = model.LastName,
                            PhoneNumber1 = model.PhoneNumber,
                            State        = model.State,
                            Surname      = model.Surname,

                            User   = user,
                            UserId = user.Id,
                        };

                        context.Guarantor.Add(guarantor);
                        await context.SaveChangesAsync();
                    }
                }
                else if (model.UserType.ToString().Equals(ApplicationRoles.EMPLOYER))
                {
                    using (var context = _context)
                    {
                        EmployerModel employer = new EmployerModel
                        {
                            Address      = model.Address,
                            Email        = model.Email,
                            FirstName    = model.FirstName,
                            Gender       = model.Gender,
                            LastName     = model.LastName,
                            PhoneNumber1 = model.PhoneNumber,
                            State        = model.State,
                            Surname      = model.Surname,
                            User         = user,
                            UserId       = user.Id,
                        };

                        context.Employer.Add(employer);
                        await context.SaveChangesAsync();
                    }
                }

                var output = await _userManager.AddToRoleAsync(user, model.UserType.ToString());

                if (output.Succeeded)
                {
                    return("User created successfully");
                }
            }
            else
            {
                return("Failed creating user");
            }

            return("Failed creating user");
        }
        private async void btnSave_Click(object sender, EventArgs e)
        {
            if (txtDuration.Text == "")
            {
                MetroFramework.MetroMessageBox.Show(this, "Warning! Please Fill-up All Required Fields.", "Loan", MessageBoxButtons.OK,
                                                    MessageBoxIcon.Error, this.Height / 2);
                return;
            }
            if (!isGenerated)
            {
                MetroFramework.MetroMessageBox.Show(this, "Warning! Invalid Loan Details", "Loan", MessageBoxButtons.OK,
                                                    MessageBoxIcon.Error, this.Height / 2);
                return;
            }
            if (int.Parse(txtDuration.Text) > 100)
            {
                MetroFramework.MetroMessageBox.Show(this, "Warning! Duration exceeds the limit", "Loan", MessageBoxButtons.OK,
                                                    MessageBoxIcon.Error, this.Height / 2);
                return;
            }
            if (!ValidateLoan())
            {
                MetroFramework.MetroMessageBox.Show(this, "Warning! Invalid Loan Details", "Loan",
                                                    MessageBoxButtons.OK, MessageBoxIcon.Error, this.Height / 2);
                return;
            }
            if (ifEmpty(gName.Text, gAddress.Text, gContacts.Text, gRelation.Text, cValue.Text, cItem.Text, cDescription.Text))
            {
                MetroFramework.MetroMessageBox.Show(this, "Warning! Please Fill Up All Fields.", "Loan",
                                                    MessageBoxButtons.OK, MessageBoxIcon.Error, this.Height / 2);
                return;
            }
            if (!ValidateNumeric(cValue.Text))
            {
                MetroFramework.MetroMessageBox.Show(this, "Warning! Collateral Value Must Be a Number.", "Loan",
                                                    MessageBoxButtons.OK, MessageBoxIcon.Error, this.Height / 2);
                return;
            }

            GuarantorModel guarantor = new GuarantorModel()
            {
                Name          = gName.Text.ToUpper(),
                Address       = gAddress.Text.ToUpper(),
                ContactNumber = gContacts.Text,
                Relationship  = gRelation.Text.ToUpper()
            };

            CollateralModel collateral = new CollateralModel()
            {
                Item        = cItem.Text.ToUpper(),
                Description = cDescription.Text.ToUpper(),
                Value       = int.Parse(cValue.Text)
            };

            if (operation != "edit" && operation != "view")
            {
                if (await loans.Add(loan, guarantor, collateral))
                {
                    await SaveLedger(loans.loanId);

                    MetroFramework.MetroMessageBox.Show(this, loans.msg, "Loan", MessageBoxButtons.OK, MessageBoxIcon.Question, this.Height / 2);
                    btnSave.Enabled = false;
                }
                else
                {
                    MetroFramework.MetroMessageBox.Show(this, loans.msg, "Loan", MessageBoxButtons.OK, MessageBoxIcon.Error, this.Height / 2);
                }
            }
            else
            {
                string token = txtLoanId.Text.Substring(4);
                loan.Id = int.Parse(token);
                if (await loans.Update(loan, guarantor, collateral))
                {
                    string token2 = txtLoanId.Text.Substring(4);
                    int    id     = int.Parse(token2);

                    MetroFramework.MetroMessageBox.Show(this, loans.msg, "Loan", MessageBoxButtons.OK, MessageBoxIcon.Question, this.Height / 2);
                    btnSave.Enabled = false;

                    groupBox1.Enabled = false;
                    groupBox3.Enabled = false;
                    btnSave.Enabled   = false;
                    btnUpdate.Enabled = true;
                    btnDelete.Enabled = true;

                    operation = "view";
                }
                else
                {
                    MetroFramework.MetroMessageBox.Show(this, loans.msg, "Loan", MessageBoxButtons.OK, MessageBoxIcon.Error, this.Height / 2);
                }
            }
        }