Ejemplo n.º 1
0
        public AddCompanyResponse addCompIndvidualModel(AddCompanyIndPayload comp, IConfiguration _config, IHostingEnvironment env)
        {
            try
            {
                using (var db = new TrippleNTDBContext())
                {
                    var checkcompany = db.Company.Where(o => o.PhoneNumber == comp.phoneNumber || o.Email == comp.email || o.Rcno == comp.rcNo).FirstOrDefault();
                    if (checkcompany != null)
                    {
                        return(checkcompany.PhoneNumber == comp.phoneNumber? new AddCompanyResponse {
                            status = "failed", msg = "Phone Number  Already Exists"
                        } :comp.rcNo == checkcompany.Rcno ? new AddCompanyResponse {
                            status = "failed", msg = "Invalid Company Reg Number"
                        }: new AddCompanyResponse {
                            status = "failed", msg = "Email Already Exists"
                        });
                    }
                    var newcomp = new Company();
                    newcomp.Name        = comp.companyName;
                    newcomp.Email       = comp.email;
                    newcomp.PhoneNumber = comp.phoneNumber;
                    newcomp.Type        = 1;
                    newcomp.RegDate     = DateTime.Now;
                    newcomp.Location    = comp.location;
                    newcomp.State       = comp.state;
                    db.Company.Add(newcomp);
                    db.SaveChanges();
                    var password = comp.password;
                    var staff    = new CompanyStaff();
                    staff.CompanyId   = newcomp.CompanyId;
                    staff.DateCreated = DateTime.Now;
                    staff.UseStatus   = false;
                    staff.Password    = Utility.Encryptor.EncodePasswordMd5(password);
                    staff.UserType    = "Admin";
                    db.CompanyStaff.Add(staff);
                    var staff1 = new CompanyStaff();
                    staff.CompanyId    = newcomp.CompanyId;
                    staff1.DateCreated = DateTime.Now;
                    staff1.UseStatus   = false;
                    staff1.Password    = Utility.Encryptor.GeneratePassword(6);
                    staff1.UserType    = "User";
                    db.CompanyStaff.Add(staff);
                    db.SaveChanges();
                    var msg = "Hello, " + comp.companyName + ", <br> We are glad to have you on our EduFund crowdfunding Platform. <br> Kindly See your credentials below <br><b>User Id: " + newcomp.PhoneNumber + "</b><br> <b>  Password: "******"  </b><br><br>#ChangeTheWorldWithYourSpareChange <br><br>Regards,<br> Admin Edufund";
                    Utility.SendMail.Send("Welcome to EduFund", msg, newcomp.Email, _config);


                    return(new AddCompanyResponse {
                        status = "success", msg = "Company Created Successfully"
                    });
                }
            }
            catch (Exception ex)
            {
                new Utility.LogWriter(ex.Message + " " + ex.InnerException, env);
                return(new AddCompanyResponse {
                    status = "failed", msg = "Something Went Wrong Try again Later"
                });
            }
        }
Ejemplo n.º 2
0
        public void CreateCompanyStaffTest()
        {
            Company     company   = new Company();
            StaffMember Employee1 = CompanyStaff.CreateMember(
                StaffMemberType.Emloyee,
                "Employee1",
                new DateTime(2017, 10, 1),
                100
                );
            StaffMember Employee2 = CompanyStaff.CreateMember(
                StaffMemberType.Emloyee,
                "Employee2",
                new DateTime(2000, 10, 1),
                100
                );
            StaffMember Manager1 = CompanyStaff.CreateMember(
                StaffMemberType.Manager,
                "Manager1",
                new DateTime(2017, 10, 1),
                100,
                new List <StaffMember>()
            {
                Employee1, Employee2
            }
                );
            StaffMember Manager2 = CompanyStaff.CreateMember(
                StaffMemberType.Manager,
                "Manager2",
                new DateTime(2000, 10, 1),
                100,
                new List <StaffMember>()
            {
                Manager1
            }
                );
            StaffMember Employee3 = CompanyStaff.CreateMember(
                StaffMemberType.Emloyee,
                "Employee3",
                new DateTime(2017, 10, 1),
                100
                );
            StaffMember Manager3 = CompanyStaff.CreateMember(
                StaffMemberType.Manager,
                "Manager3",
                new DateTime(2017, 10, 1),
                100,
                new List <StaffMember>()
            {
                Employee3
            }
                );
            StaffMember Sales1 = CompanyStaff.CreateMember(
                StaffMemberType.Sales,
                "Sales1",
                new DateTime(2017, 10, 1),
                100,
                new List <StaffMember>()
            {
                Manager2, Manager3
            }
                );

            company.BoardMembers.Add(Sales1);
            Assert.AreEqual(Employee1.CurrentSalary(), 103);
            Assert.AreEqual(Employee2.CurrentSalary(), 130);
            Assert.AreEqual(Manager1.CurrentSalary(), 106.165);
            Assert.AreEqual(Manager2.CurrentSalary(), 140.530825);
            Assert.AreEqual(Employee3.CurrentSalary(), 103);
            Assert.AreEqual(Manager3.CurrentSalary(), 105.515);
            Assert.AreEqual(Sales1.CurrentSalary(), 103.064632475);
            Assert.AreEqual(Math.Round(company.getSalariesSum(), 9), 791.275457475);
        }
Ejemplo n.º 3
0
        // OAuthAuthorizationServerProvider sınıfının kaynak erişimine izin verebilmek için ilgili GrantResourceOwnerCredentials metotunu override ediyoruz.
        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            // User verify
            ModelContainer _contextModel = new ModelContainer();

            string email = context.UserName.ToString();

            Admin admin = (from c in _contextModel.Admin.AsNoTracking() where c.Email == email select c).FirstOrDefault();

            Company      company = (from c in _contextModel.Company.AsNoTracking() where c.Email == email select c).FirstOrDefault();
            CompanyStaff staff   = (from c in _contextModel.CompanyStaff.AsNoTracking() where c.Email == email select c).FirstOrDefault();

            if (admin != null)
            {
                if (context.UserName == admin.Email && VerifyPasswordHash(context.Password.ToString(), admin.PasswordHash, admin.PasswordSalt))
                {
                    // CORS ayarlarını set ediyoruz.
                    context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });

                    // Kullanıcının access_token alabilmesi için gerekli validation işlemlerini yapıyoruz.
                    var identity = new ClaimsIdentity(context.Options.AuthenticationType);

                    identity.AddClaim(new Claim("adminID", admin.ID.ToString()));
                    identity.AddClaim(new Claim("userName", context.UserName));
                    identity.AddClaim(new Claim("role", "admin"));

                    context.Validated(identity);
                }
                else
                {
                    context.SetError("invalid_grant", "The Username or Password is incorrect");
                }
            }
            else if (company != null)
            {
                if (context.UserName == company.Email && VerifyPasswordHash(context.Password.ToString(), company.PasswordHash, company.PasswordSalt))
                {
                    // CORS ayarlarını set ediyoruz.
                    context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });

                    // Kullanıcının access_token alabilmesi için gerekli validation işlemlerini yapıyoruz.
                    var identity = new ClaimsIdentity(context.Options.AuthenticationType);

                    identity.AddClaim(new Claim("companyID", company.ID.ToString()));
                    identity.AddClaim(new Claim("userName", context.UserName));
                    identity.AddClaim(new Claim("role", "company"));

                    context.Validated(identity);
                }
                else
                {
                    context.SetError("invalid_grant", "The Username or Password is incorrect");
                }
            }
            else if (staff != null)
            {
                if (context.UserName == staff.Email && VerifyPasswordHash(context.Password.ToString(), staff.PasswordHash, staff.PasswordSalt))
                {
                    // CORS ayarlarını set ediyoruz.
                    context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });

                    // Kullanıcının access_token alabilmesi için gerekli validation işlemlerini yapıyoruz.
                    var identity = new ClaimsIdentity(context.Options.AuthenticationType);

                    identity.AddClaim(new Claim("companyID", staff.CompanyID.ToString()));
                    identity.AddClaim(new Claim("userName", context.UserName));
                    identity.AddClaim(new Claim("role", "staff"));
                    identity.AddClaim(new Claim("staffID", staff.ID.ToString()));

                    context.Validated(identity);
                }
                else
                {
                    context.SetError("invalid_grant", "The Username or Password is incorrect");
                }
            }
            else
            {
                context.SetError("invalid_grant", "The Username or Password is incorrect");
            }
        }
Ejemplo n.º 4
0
        public AuthorizedDto Login([Required] string email, [Required] string password)
        {
            if (!ModelState.IsValid)
            {
                return(null);
            }

            try
            {
                Admin        admin   = (from c in context.Admin.AsNoTracking() where c.Email == email select c).FirstOrDefault();
                Company      company = (from c in context.Company.AsNoTracking() where c.Email == email select c).FirstOrDefault();
                CompanyStaff staff   = (from c in context.CompanyStaff.AsNoTracking() where c.Email == email select c).FirstOrDefault();

                if (admin == null && company == null && staff == null)
                {
                    return(null);
                }

                string strLocalUrl = "http://localhost:50894";

                WebRequest webRequest = WebRequest.Create(strLocalUrl + "/token");
                webRequest.Method      = "POST";
                webRequest.ContentType = "application/x-www-form-urlencoded";

                byte[] byteBody = new ASCIIEncoding().GetBytes("grant_type=password&username="******"&password="******"admin",
                        Token = authTokenDto.access_token,
                    });
                }
                else if (company != null)
                {
                    return(new AuthorizedDto()
                    {
                        ID = company.ID,
                        Name = company.Name,
                        Email = company.Email,
                        ImageUrl = company.ImageUrl,
                        Role = "company",
                        Token = authTokenDto.access_token,
                    });
                }
                else if (staff != null)
                {
                    return(new AuthorizedDto()
                    {
                        ID = staff.ID,
                        ParentID = staff.CompanyID,
                        Name = staff.Name,
                        Email = staff.Email,
                        ImageUrl = staff.ImageUrl,
                        Role = "staff",
                        Token = authTokenDto.access_token,
                    });
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception)
            {
                return(null);
            }
        }