Ejemplo n.º 1
0
        public async Task <ActionResult> Edit(int id, VmUserItem _vmObject)
        {
            var roleListArr = Request.Form["RoleList"].ToArray();

            for (int i = 0; i < roleListArr.Length; i++)
            {
                VmRoleItem _lst = new VmRoleItem();

                if (roleListArr[i].ToString().All(char.IsDigit))
                {
                    _lst.Id = int.Parse(roleListArr[i]);
                    _vmObject.RoleList.Add(_lst);
                }
            }

            if (id != _vmObject.Id)
            {
                return(NotFound());
            }

            var result = await svs.Update(_vmObject);

            if (result.IsSuccess)
            {
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                return(View(_vmObject));
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Index(VmUserItem user)
        {
            string[] serviceTags;
            serviceTags = Request.Form["serviceTags"].ToArray();

            var result = await userService.Register(user, serviceTags);

            if (result.IsSuccess)
            {
                string mailBody         = "";
                string confirmationLink = "";

                //var location = new Uri($"{Request.Scheme}://{Request.Host}{Request.Path}{Request.QueryString}");
                var    location    = new Uri($"{Request.Scheme}://{Request.Host}");
                var    url         = location.AbsoluteUri;
                string encodeEmail = user.EmailAddress.EncodeString(); // Convert.ToBase64String(Encoding.UTF8.GetBytes(user.EmailAddress));
                string token       = _appSettings.App_Identity.Identity;
                //var byte_time = Encoding.UTF8.GetBytes(DateTime.Now.AddDays(2).ToString());
                string encodeTimeLimit = DateTime.Now.AddDays(2).ToString().EncodeString(); // Convert.ToBase64String(byte_time);
                confirmationLink = url + "Registration/ConfirmUser?token=" + token + "&e=" + encodeEmail + "&t=" + encodeTimeLimit;

                mailBody = "Please confirm your account by clicking the following link \n " + confirmationLink;
                SendingMail sm = new SendingMail();
                sm.SendMail(user.EmailAddress, "", "Confirmation for Registration", mailBody);
                return(RedirectToAction("SuccessRegistration"));
            }
            else
            {
                return(View());
            }
        }
Ejemplo n.º 3
0
        public async Task <VmUserItem> ValidateUser(VM_Sys_User_Sign_In user)
        {
            var dbresult = await repo.GetUser(user.UserName, Md5.Encrypt(user.Password));

            if (dbresult == null)
            {
                return(new VmUserItem());
            }
            else
            {
                var result = new VmUserItem();
                Copy <Com.BudgetMetal.DBEntities.User, VmUserItem>(dbresult, result);

                if (dbresult.UserRoles != null)
                {
                    var SelectedRoles = new List <VmRoleItem>();
                    foreach (var dbItem in dbresult.UserRoles)
                    {
                        var resultUserRoles = new VmRoleItem();
                        var dbRole          = await roleRepo.Get(dbItem.Role_Id);

                        Copy <Com.BudgetMetal.DBEntities.Role, VmRoleItem>(dbRole, resultUserRoles);

                        SelectedRoles.Add(resultUserRoles);
                    }
                    result.SelectedRoles = SelectedRoles;
                }

                var resultCompany = new VmCompanyItem();
                Copy <Com.BudgetMetal.DBEntities.Company, VmCompanyItem>(dbresult.Company, resultCompany);
                result.Company = resultCompany;

                return(result);
            }
        }
Ejemplo n.º 4
0
        public async Task <bool> CheckUserName(string UserName)
        {
            var dbresult = await repo.GetUserByUserName(UserName);

            if (dbresult == null)
            {
                return(false);
            }
            else
            {
                var result = new VmUserItem();
                Copy <Com.BudgetMetal.DBEntities.User, VmUserItem>(dbresult, result);

                return(true);
            }
        }
Ejemplo n.º 5
0
        public async Task <VmUserPage> GetUserByPage(string keyword, int page, int totalRecords)
        {
            var dbPageResult = await repo.GetPage(keyword,
                                                  (page == 0 ? Constants.app_firstPage : page),
                                                  (totalRecords == 0 ? Constants.app_totalRecords : totalRecords));

            if (dbPageResult == null)
            {
                return(new VmUserPage());
            }

            var resultObj = new VmUserPage();

            //resultObj.ApplicationToken = applicationToken;
            resultObj.RequestId      = DateTime.Now.ToString("yyyyMMddHHmmss");
            resultObj.RequestDate    = DateTime.Now;
            resultObj.Result         = new PageResult <VmUserItem>();
            resultObj.Result.Records = new List <VmUserItem>();

            Copy <PageResult <User>, PageResult <VmUserItem> >(dbPageResult, resultObj.Result, new string[] { "Records" });

            foreach (var dbItem in dbPageResult.Records)
            {
                var resultItem = new VmUserItem();

                Copy <User, VmUserItem>(dbItem, resultItem);

                if (dbItem.Company != null)
                {
                    resultItem.Company = new ViewModels.Company.VmCompanyItem()
                    {
                        Name = dbItem.Company.Name
                    };
                }
                if (dbItem.CodeTable != null)
                {
                    resultItem.CodeTable = new ViewModels.CodeTable.VmCodeTableItem()
                    {
                        Name = dbItem.CodeTable.Name
                    };
                }

                resultObj.Result.Records.Add(resultItem);
            }

            return(resultObj);
        }
Ejemplo n.º 6
0
        public async Task <List <VmUserItem> > GetUserByCompany(int Id)
        {
            var dbResult = await repo.GetUserByCompany(Id);

            var resultList = new List <VmUserItem>();

            foreach (var item in dbResult)
            {
                var result = new VmUserItem();

                Copy <Com.BudgetMetal.DBEntities.User, VmUserItem>(item, result);

                resultList.Add(result);
            }


            return(resultList);
        }
Ejemplo n.º 7
0
        public async Task <VmGenericServiceResult> Update(VmUserItem vObj)
        {
            VmGenericServiceResult result = new VmGenericServiceResult();

            try
            {
                Com.BudgetMetal.DBEntities.User dbObj = await repo.Get(vObj.Id);

                Copy <VmUserItem, Com.BudgetMetal.DBEntities.User>(vObj, dbObj);

                if (vObj.RoleList != null && vObj.RoleList.Count > 0)
                {
                    foreach (var vUsrRole in vObj.RoleList)
                    {
                        var dbRoleObj = await roleRepo.Get(vUsrRole.Id);

                        if (dbRoleObj != null)
                        {
                            UserRoles ur = new UserRoles();
                            ur.Role = dbRoleObj;
                            ur.PrepareNewRecord("System");
                            dbObj.UserRoles.Add(ur);
                        }
                    }
                }
                dbObj.PrepareNewRecord("System");
                repo.Update(dbObj);

                repo.Commit();

                result.IsSuccess = true;
            }
            catch (Exception e)
            {
                result.IsSuccess = false;
                result.Error     = e;
            }

            return(result);
        }
Ejemplo n.º 8
0
        public async Task <bool> CheckCurrentPassword(int id, string currentPassword)
        {
            var dbresult = await repo.GetUserById(id);

            if (dbresult == null)
            {
                return(false);
            }
            else
            {
                if (dbresult.Password == Md5.Encrypt(currentPassword))
                {
                    var result = new VmUserItem();
                    Copy <Com.BudgetMetal.DBEntities.User, VmUserItem>(dbresult, result);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Ejemplo n.º 9
0
        public async Task <VmCompanyItem> GetCompanyProfileById(int Id)
        {
            var dbPageResult = await repo.Get(Id);

            if (dbPageResult == null)
            {
                return(new VmCompanyItem());
            }

            var resultObj = new VmCompanyItem();

            Copy <Com.BudgetMetal.DBEntities.Company, VmCompanyItem>(dbPageResult, resultObj);

            resultObj.IsVerified = (dbPageResult.IsVerified == null) ? false : (bool)dbPageResult.IsVerified;

            var dbUserList = await repoUser.GetUserByCompanyNotFilterWithConfirm(Id);

            if (dbUserList == null)
            {
                return(resultObj);
            }

            resultObj.UserList = new List <VmUserItem>();

            foreach (var dbUser in dbUserList)
            {
                List <VmRoleItem> rListItem = new List <VmRoleItem>();
                if (dbUser.UserRoles != null)
                {
                    foreach (var dbRoleItem in dbUser.UserRoles)
                    {
                        var dbRole = roleRepository.Get(dbRoleItem.Role_Id);
                        if (dbRole != null)
                        {
                            VmRoleItem rItem = new VmRoleItem();
                            rItem.Id   = dbRole.Result.Id;
                            rItem.Name = dbRole.Result.Name;
                            rItem.Code = dbRole.Result.Code;
                            rListItem.Add(rItem);
                        }
                    }
                }
                VmUserItem user = new VmUserItem()
                {
                    Id           = dbUser.Id,
                    UserName     = dbUser.UserName,
                    EmailAddress = dbUser.EmailAddress,
                    JobTitle     = dbUser.JobTitle,
                    UserType     = dbUser.UserType,
                    IsConfirmed  = dbUser.IsConfirmed,
                    IsActive     = dbUser.IsActive,
                    RoleList     = rListItem
                };

                resultObj.UserList.Add(user);
            }

            var dbRepoList = await ratingRepo.GetRagintByCompany(Id);

            if (dbRepoList == null)
            {
                return(resultObj);
            }

            resultObj.RatingList = new List <VmRatingItem>();
            foreach (var dbRating in dbRepoList)
            {
                VmRatingItem rating = new VmRatingItem()
                {
                    SpeedOfQuotation  = dbRating.SpeedOfQuotation,
                    SpeedofDelivery   = dbRating.SpeedofDelivery,
                    ServiceQuality    = dbRating.ServiceQuality,
                    Price             = dbRating.Price,
                    SpeedofProcessing = dbRating.SpeedofProcessing,
                    Payment           = dbRating.Payment,
                    Title             = dbRating.Title,
                    Description       = dbRating.Description,
                    Ratingcol         = dbRating.Ratingcol,
                    UserName          = dbRating.User.ContactName
                };
                //var rating = new VmRatingItem();
                //Copy<Com.BudgetMetal.DBEntities.Rating, VmRatingItem>(dbRating, rating);
                resultObj.RatingList.Add(rating);
            }

            return(resultObj);
        }
Ejemplo n.º 10
0
        public async Task <VmGenericServiceResult> Register(VmUserItem user, string[] serviceTags)
        {
            var result = new VmGenericServiceResult();

            try
            {
                int companyId = 0;
                if (user.Company.Id > 0)
                {
                    companyId = user.Company.Id;
                }
                else
                {
                    var dbCompany = new Com.BudgetMetal.DBEntities.Company();
                    Copy <VmCompanyItem, Com.BudgetMetal.DBEntities.Company>(user.Company, dbCompany);

                    var dbMaxDefaultRFQ = await CTrepo.Get(Constants_CodeTable.Code_MaxDefaultRFQPerWeek);

                    dbCompany.MaxRFQPerWeek = Convert.ToInt32(dbMaxDefaultRFQ.Value);

                    var dbMaxDefaultQuote = await CTrepo.Get(Constants_CodeTable.Code_MaxDefaultQuotePerWeek);

                    dbCompany.MaxQuotationPerWeek = Convert.ToInt32(dbMaxDefaultQuote.Value);

                    dbCompany.IsVerified        = false;
                    dbCompany.SupplierAvgRating = dbCompany.BuyerAvgRating = dbCompany.AwardedQuotation = dbCompany.SubmittedQuotation = 0;
                    dbCompany.C_BusinessType    = Constants_CodeTable.Code_C_Supplier;
                    dbCompany.CreatedBy         = dbCompany.UpdatedBy = user.UserName;
                    var dbResultCompany = cRepo.Add(dbCompany);
                    cRepo.Commit();
                    companyId = dbResultCompany.Id;

                    if (serviceTags != null)
                    {
                        foreach (var item in serviceTags)
                        {
                            var dbSupplierServicTags = new SupplierServiceTags();
                            dbSupplierServicTags.Company_Id     = companyId;
                            dbSupplierServicTags.ServiceTags_Id = Convert.ToInt32(item);
                            dbSupplierServicTags.CreatedBy      = dbSupplierServicTags.UpdatedBy = user.UserName;

                            supplierServiceTagsRepo.Add(dbSupplierServicTags);
                        }
                        supplierServiceTagsRepo.Commit();
                    }
                }

                var dbUser = new User();
                Copy <VmUserItem, Com.BudgetMetal.DBEntities.User>(user, dbUser, new string[] { "Company" });
                dbUser.Company_Id  = companyId;
                dbUser.Password    = Common.Md5.Encrypt(dbUser.Password);
                dbUser.CreatedBy   = dbUser.UpdatedBy = user.UserName;
                dbUser.IsConfirmed = false;
                dbUser.UserType    = Constants_CodeTable.Code_Supplier;

                var dbResultUser = repo.Add(dbUser);
                repo.Commit();

                result.IsSuccess     = true;
                result.MessageToUser = user.EmailAddress;
            }
            catch (Exception ex)
            {
                result.IsSuccess     = false;
                result.MessageToUser = ex.Message;
                result.Error         = ex;
            }

            return(result);
        }
Ejemplo n.º 11
0
        public async Task <VmUserItem> GetFormObject()
        {
            VmUserItem result = new VmUserItem();

            var dbCList = await cRepo.GetAll();

            //filter with companyId
            var dbCCList = await CTrepo.GetAll();

            var dbRoleList = await roleRepo.GetAll();

            if (dbCList == null && dbCCList == null && dbRoleList == null)
            {
                return(result);
            }

            if (dbCList != null)
            {
                result.CompanyList = new List <VmCompanyItem>();

                foreach (var dbcat in dbCList)
                {
                    VmCompanyItem _company = new VmCompanyItem()
                    {
                        Id   = dbcat.Id,
                        Name = dbcat.Name
                    };

                    result.CompanyList.Add(_company);
                }
            }
            if (dbCCList != null)
            {
                result.CodeTableList = new List <VmCodeTableItem>();

                foreach (var dbcat in dbCCList)
                {
                    VmCodeTableItem _codeTable = new VmCodeTableItem()
                    {
                        Id   = dbcat.Id,
                        Name = dbcat.Name
                    };

                    result.CodeTableList.Add(_codeTable);
                }
            }
            if (dbRoleList != null)
            {
                result.RoleList = new List <VmRoleItem>();

                foreach (var item in dbRoleList)
                {
                    VmRoleItem _roleItem = new VmRoleItem()
                    {
                        Id   = item.Id,
                        Name = item.Name
                    };

                    result.RoleList.Add(_roleItem);
                }
            }

            return(result);
        }
Ejemplo n.º 12
0
        public async Task <VmGenericServiceResult> Insert(VmUserItem vObj)
        {
            VmGenericServiceResult result = new VmGenericServiceResult();

            try
            {
                Com.BudgetMetal.DBEntities.User dbObj = new Com.BudgetMetal.DBEntities.User();

                Copy <VmUserItem, Com.BudgetMetal.DBEntities.User>(vObj, dbObj);

                #region comments
                // r.Industry_Id = 1;//hard code
                //var user = new[]
                //{
                //    new User { Id = r.Id },
                //    //new User {Id = 2}
                //};
                ////var role = new Role { Id = 1 };
                ////var role1 = new Role { Id = 2 };

                //var role = new[]
                //{
                //    new Role {Id=1},
                //    new Role {Id=2}
                //};
                //r.UserRoles.Add(new UserRoles { User = user[0], Role = role[0] });

                //r.UserRoles.Add(new UserRoles { User = user, Role = role1 });


                //foreach (var post in UserRoles)
                //{
                //    var oldPostTag = post.PostTags.FirstOrDefault(e => e.Tag.Text == "Pineapple");
                //    if (oldPostTag != null)
                //    {
                //        post.PostTags.Remove(oldPostTag);
                //        post.PostTags.Add(new PostTag { Post = post, Tag = newTag1 });
                //    }
                //    post.PostTags.Add(new PostTag { Post = post, Tag = newTag2 });
                //}
                //UserRoles _userRole = new UserRoles();
                ////_userRole.User = user[0];
                //_userRole.User_Id = r.Id;
                //_userRole.Role_Id = 1;
                ////_userRole.Role = role[0];
                //userRolesRepo.Add(_userRole);
                //userRolesRepo.Commit();
                #endregion

                if (vObj.RoleList != null && vObj.RoleList.Count > 0)
                {
                    foreach (var vUsrRole in vObj.RoleList)
                    {
                        var dbRoleObj = await roleRepo.Get(vUsrRole.Id);

                        if (dbRoleObj != null)
                        {
                            UserRoles ur = new UserRoles();
                            ur.Role = dbRoleObj;
                            ur.PrepareNewRecord("System");
                            dbObj.UserRoles.Add(ur);
                        }
                    }
                }
                dbObj.PrepareNewRecord("System");

                repo.Add(dbObj);

                repo.Commit();

                result.IsSuccess = true;
            }
            catch (Exception e)
            {
                result.IsSuccess = false;
                result.Error     = e;
            }

            return(result);
        }
Ejemplo n.º 13
0
        public async Task <VmUserItem> GetUserById(int Id)
        {
            var dbPageResult = await repo.GetUserById(Id);

            if (dbPageResult == null)
            {
                return(new VmUserItem());
            }

            var result = new VmUserItem();

            Copy <Com.BudgetMetal.DBEntities.User, VmUserItem>(dbPageResult, result);

            var dbCList = await cRepo.GetAll();

            //filter with companyId
            var dbCCList = await CTrepo.GetAll();

            var dbRoleList = await roleRepo.GetAll();

            if (dbCList == null && dbCCList == null && dbRoleList == null)
            {
                return(result);
            }

            if (dbCList != null)
            {
                result.CompanyList = new List <VmCompanyItem>();

                foreach (var dbcat in dbCList)
                {
                    VmCompanyItem _company = new VmCompanyItem()
                    {
                        Id   = dbcat.Id,
                        Name = dbcat.Name
                    };

                    result.CompanyList.Add(_company);
                }
            }
            if (dbCCList != null)
            {
                result.CodeTableList = new List <VmCodeTableItem>();

                foreach (var dbcat in dbCCList)
                {
                    VmCodeTableItem _codeTable = new VmCodeTableItem()
                    {
                        Id   = dbcat.Id,
                        Name = dbcat.Name
                    };

                    result.CodeTableList.Add(_codeTable);
                }
            }
            if (dbRoleList != null)
            {
                result.RoleList = new List <VmRoleItem>();

                foreach (var item in dbRoleList)
                {
                    VmRoleItem _roleItem = new VmRoleItem()
                    {
                        Id   = item.Id,
                        Name = item.Name
                    };

                    result.RoleList.Add(_roleItem);
                }
            }

            if (dbPageResult.UserRoles != null)
            {
                if (dbPageResult.UserRoles.Count > 0)
                {
                    result.SelectedRoleId = new List <int>();
                    foreach (var item in dbPageResult.UserRoles)
                    {
                        int roleId = item.Role_Id;
                        result.SelectedRoleId.Add(roleId);
                    }
                }
                else
                {
                    //Add zero
                    result.SelectedRoleId = new List <int>();
                    result.SelectedRoleId.Add(0);
                }
            }

            return(result);
        }