Exemplo n.º 1
0
        public async Task <VmGenericServiceResult> Update(VmDocumentItem vmItem)
        {
            VmGenericServiceResult result = new VmGenericServiceResult();

            try
            {
                Com.BudgetMetal.DBEntities.Document entity = await documentRepo.Get(vmItem.Id);

                Copy <VmDocumentItem, Com.BudgetMetal.DBEntities.Document>(vmItem, entity);

                if (entity.UpdatedBy.IsNullOrEmpty())
                {
                    entity.UpdatedBy = "System";
                }

                documentRepo.Update(entity);

                documentRepo.Commit();

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

            return(result);
        }
Exemplo n.º 2
0
        public VmGenericServiceResult Insert(VmDocumentItem vmItem)
        {
            VmGenericServiceResult result = new VmGenericServiceResult();

            try
            {
                Com.BudgetMetal.DBEntities.Document entity = new Com.BudgetMetal.DBEntities.Document();

                Copy <VmDocumentItem, Com.BudgetMetal.DBEntities.Document>(vmItem, entity);

                entity.Company_Id        = (int)vmItem.Company_Id;
                entity.DocumentStatus_Id = (int)vmItem.DocumentStatus_Id;
                entity.DocumentType_Id   = (int)vmItem.DocumentType_Id;
                if (entity.CreatedBy.IsNullOrEmpty())
                {
                    entity.CreatedBy = entity.UpdatedBy = "System";
                }
                documentRepo.Add(entity);

                documentRepo.Commit();

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

            return(result);
        }
Exemplo n.º 3
0
        public VmGenericServiceResult Insert(VmEmailLogItem vmtem)
        {
            VmGenericServiceResult result = new VmGenericServiceResult();

            try
            {
                Com.BudgetMetal.DBEntities.EmailLog r = new Com.BudgetMetal.DBEntities.EmailLog();

                Copy <VmEmailLogItem, Com.BudgetMetal.DBEntities.EmailLog>(vmtem, r);

                if (r.CreatedBy.IsNullOrEmpty())
                {
                    r.CreatedBy = r.UpdatedBy = "System";
                }

                repo.Add(r);

                repo.Commit();

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

            return(result);
        }
Exemplo n.º 4
0
        public async Task <VmGenericServiceResult> Update(VmCodeTableItem vmCodeTableItem)
        {
            VmGenericServiceResult result = new VmGenericServiceResult();

            try
            {
                CodeTable r = await repo.Get(vmCodeTableItem.Id);

                Copy <VmCodeTableItem, CodeTable>(vmCodeTableItem, r);

                if (r.UpdatedBy.IsNullOrEmpty())
                {
                    r.UpdatedBy = "System";
                }

                repo.Update(r);

                repo.Commit();

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

            return(result);
        }
Exemplo n.º 5
0
        public async Task <VmGenericServiceResult> Update(VmCompanyItem vmCompanyItem)
        {
            VmGenericServiceResult result = new VmGenericServiceResult();

            try
            {
                Com.BudgetMetal.DBEntities.Company r = await repo.Get(vmCompanyItem.Id);

                Copy <VmCompanyItem, Com.BudgetMetal.DBEntities.Company>(vmCompanyItem, r);

                if (r.UpdatedBy.IsNullOrEmpty())
                {
                    r.UpdatedBy = "System";
                }

                r.IsVerified = vmCompanyItem.IsVerified;

                repo.Update(r);

                repo.Commit();

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

            return(result);
        }
Exemplo n.º 6
0
        public VmGenericServiceResult Insert(VmServiceTagsItem vmtem)
        {
            VmGenericServiceResult result = new VmGenericServiceResult();

            try
            {
                Com.BudgetMetal.DBEntities.ServiceTags r = new Com.BudgetMetal.DBEntities.ServiceTags();

                Copy <VmServiceTagsItem, Com.BudgetMetal.DBEntities.ServiceTags>(vmtem, r);

                if (r.CreatedBy.IsNullOrEmpty())
                {
                    r.CreatedBy = r.UpdatedBy = "System";
                }
                // r.Industry_Id = 1;//hard code
                repo.Add(r);

                repo.Commit();

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

            return(result);
        }
Exemplo n.º 7
0
        public async Task <VmGenericServiceResult> Insert(VmRatingItem vmRatingItem)
        {
            VmGenericServiceResult result = new VmGenericServiceResult();

            try
            {
                BudgetMetal.DBEntities.Rating r = new BudgetMetal.DBEntities.Rating();

                Copy <VmRatingItem, BudgetMetal.DBEntities.Rating>(vmRatingItem, r);

                if (r.CreatedBy.IsNullOrEmpty())
                {
                    r.CreatedBy = r.UpdatedBy = "System";
                }

                repo.Add(r);

                repo.Commit();

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

            return(result);
        }
Exemplo n.º 8
0
        public VmGenericServiceResult Insert(VmCodeTableItem vmCodeTableItem)
        {
            VmGenericServiceResult result = new VmGenericServiceResult();

            try
            {
                CodeTable r = new CodeTable();

                Copy <VmCodeTableItem, CodeTable>(vmCodeTableItem, r);

                r.CodeCategory_Id = (int)vmCodeTableItem.CodeCategory_Id;
                if (r.CreatedBy.IsNullOrEmpty())
                {
                    r.CreatedBy = r.UpdatedBy = "System";
                }
                repo.Add(r);

                repo.Commit();

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

            return(result);
        }
Exemplo n.º 9
0
        public VmGenericServiceResult Insert(VmIndustryItem vmtem)
        {
            VmGenericServiceResult result = new VmGenericServiceResult();

            try
            {
                Industry r = new Industry();

                Copy <VmIndustryItem, Industry>(vmtem, r);

                if (r.CreatedBy.IsNullOrEmpty())
                {
                    r.CreatedBy = r.UpdatedBy = "System";
                }

                repo.Add(r);

                repo.Commit();

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

            return(result);
        }
Exemplo n.º 10
0
        public async Task <VmGenericServiceResult> ResetPassword(string username)
        {
            var result = new VmGenericServiceResult();

            var dbresult = await repo.GetUserByUserNameOrEmail(username);



            if (dbresult == null)
            {
                result.IsSuccess     = false;
                result.MessageToUser = "******";
            }
            else
            {
                //dbresult.Password = Md5.Encrypt(newPassword);
                //repo.Update(dbresult);
                //repo.Commit();
                result.IsSuccess = true;
                //generate reset password link
                string link = "";
                string encryptedUserName  = System.Net.WebUtility.UrlEncode(Md5.Encrypt(dbresult.UserName));
                string encryptedValidDate = System.Net.WebUtility.UrlEncode(Md5.Encrypt(DateTime.Now.ToString("yyyy-mm-dd")));
                link = "u=" + encryptedUserName + "&d=" + encryptedValidDate;

                result.MessageToUser = dbresult.EmailAddress + ",#," + link;
                //result.MessageToUser = "******" + dbresult.EmailAddress+").";
            }

            return(result);
        }
Exemplo n.º 11
0
        public async Task <VmGenericServiceResult> ConfirmUserName(string Username)
        {
            var result = new VmGenericServiceResult();

            var dbresult = await repo.GetUserByUserName(Username);

            if (dbresult == null)
            {
                result.IsSuccess     = false;
                result.MessageToUser = "******";
            }
            else
            {
                if (dbresult.IsConfirmed)
                {
                    result.IsSuccess     = false;
                    result.MessageToUser = "******";
                }
                else
                {
                    dbresult.IsConfirmed = true;
                    repo.Update(dbresult);
                    repo.Commit();
                    result.IsSuccess     = true;
                    result.MessageToUser = "******";
                }
            }

            return(result);
        }
Exemplo n.º 12
0
        public async Task <VmGenericServiceResult> EditCompanyUserRole(int companyId, int userId, string[] userRole, string updatedBy)
        {
            var    result     = new VmGenericServiceResult();
            string roleName   = "";
            var    dbRoleUser = userRoleRepository.GetUserRolesByUserId(userId);

            if (dbRoleUser != null)
            {
                foreach (var item in dbRoleUser.Result)
                {
                    DBEntities.UserRoles userRoles = await userRoleRepository.Get(item.Id);

                    userRoleRepository.Delete(userRoles);
                }
                userRoleRepository.Commit();
            }

            foreach (var role in userRole)
            {
                if (role != null)
                {
                    int roleId           = int.Parse(role);
                    var dbRoleUserResult = await userRoleRepository.GetUserRolesByUserIdRoleId(userId, roleId);

                    if (dbRoleUserResult == null)
                    {
                        DBEntities.UserRoles userRoles = new DBEntities.UserRoles();
                        userRoles.User_Id   = userId;
                        userRoles.IsActive  = true;
                        userRoles.UpdatedBy = updatedBy;
                        userRoles.Role_Id   = roleId;
                        userRoleRepository.Add(userRoles);
                    }
                    else
                    {
                        dbRoleUserResult.IsActive  = true;
                        dbRoleUserResult.UpdatedBy = updatedBy;
                        dbRoleUserResult.Role_Id   = roleId;
                        userRoleRepository.Update(dbRoleUserResult);
                    }
                    var roleEntity = roleRepository.Get(roleId);
                    if (roleEntity != null)
                    {
                        roleName += roleEntity.Result.Name + "|";
                    }
                    result.IsSuccess = true;
                }
                else
                {
                    result.IsSuccess = true;
                }
            }
            result.MessageToUser = roleName.TrimEnd('|');
            userRoleRepository.Commit();
            return(result);
        }
Exemplo n.º 13
0
        public VmGenericServiceResult Insert(VmCompanyItem vmItem)
        {
            VmGenericServiceResult result = new VmGenericServiceResult();

            try
            {
                Com.BudgetMetal.DBEntities.Company r = new Com.BudgetMetal.DBEntities.Company();

                Copy <VmCompanyItem, Com.BudgetMetal.DBEntities.Company>(vmItem, r);

                r.IsVerified         = false;
                r.AwardedQuotation   = 0;
                r.SubmittedQuotation = 0;
                r.BuyerAvgRating     = 0;
                r.SupplierAvgRating  = 0;

                //Max Default RFQ Per Week
                var codeTableRepo = this.codeTableRepo.Get(10100001);

                int maxQuotationPerWeek = Convert.ToInt32(codeTableRepo.Result.Value);

                //Max Default Quote Per Week
                codeTableRepo = this.codeTableRepo.Get(10100002);

                int maxRFQPerWeek = Convert.ToInt32(codeTableRepo.Result.Value);

                r.MaxQuotationPerWeek = maxQuotationPerWeek;
                r.MaxRFQPerWeek       = maxRFQPerWeek;

                if (r.CreatedBy.IsNullOrEmpty())
                {
                    r.CreatedBy = r.UpdatedBy = "System";
                }
                repo.Add(r);

                repo.Commit();

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

            return(result);
        }
Exemplo n.º 14
0
        public async Task <VmGenericServiceResult> PostMessage(string message)
        {
            var result = new VmGenericServiceResult();

            try
            {
                //var appIdTask = repoCodeTable.Get(Constants_CodeTable.Code_SiteOption_Fb_App_Id);
                //var secretTask = repoCodeTable.Get(Constants_CodeTable.Code_SiteOption_Fb_App_Secret);
                var PageIdTask = repoCodeTable.Get(Constants_CodeTable.Code_SiteOption_Fb_PageId);

                //Task.WaitAll(new[] { appIdTask, secretTask, PageIdTask });

                Task.WaitAll(new[] { PageIdTask });

                //string app_id = appIdTask.Result.Value;
                //string app_secret = secretTask.Result.Value;


                string accessToken = await GetAccessTokenAsync();

                string page_id    = PageIdTask.Result.Value;
                string app_id     = _appId;
                string app_secret = _secret;
                var    client     = new FacebookClient(accessToken);
                client.AppId     = app_id;
                client.AppSecret = app_secret;

                dynamic parameters = new ExpandoObject();
                parameters.message = message;

                client.Post("/" + page_id + "/feed", parameters);
                result.IsSuccess     = true;
                result.MessageToUser = "******";
            }
            catch (Exception ex)
            {
                result.IsSuccess     = false;
                result.MessageToUser = "******" + ex.Message;
                result.Error         = ex;
            }

            return(result);
        }
Exemplo n.º 15
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);
        }
Exemplo n.º 16
0
        public async Task <VmGenericServiceResult> EditCompanyUser(int companyId, int userId, bool isActiveStatus, string updatedBy)
        {
            var result = new VmGenericServiceResult();

            var dbresult = await repoUser.GetUserCompanyIdandUserId(companyId, userId);

            if (dbresult == null)
            {
                result.IsSuccess     = false;
                result.MessageToUser = "******";
            }
            else
            {
                dbresult.IsConfirmed = isActiveStatus;
                dbresult.UpdatedBy   = updatedBy;
                repoUser.Update(dbresult);
                repoUser.Commit();
                result.IsSuccess     = true;
                result.MessageToUser = "******";
            }
            return(result);
        }
Exemplo n.º 17
0
        public async Task <VmGenericServiceResult> EditCompanyAddress(int companyId, string address, string updatedBy)
        {
            var result = new VmGenericServiceResult();

            var dbresult = await repo.Get(companyId);

            if (dbresult == null)
            {
                result.IsSuccess     = false;
                result.MessageToUser = "******";
            }
            else
            {
                dbresult.Address   = address;
                dbresult.UpdatedBy = updatedBy;
                repo.Update(dbresult);
                repo.Commit();
                result.IsSuccess     = true;
                result.MessageToUser = "******";
            }
            return(result);
        }
Exemplo n.º 18
0
        public async Task <VmGenericServiceResult> ChangePassword(int id, string password)
        {
            var result = new VmGenericServiceResult();

            var dbresult = await repo.GetUserById(id);

            if (dbresult == null)
            {
                result.IsSuccess     = false;
                result.MessageToUser = "******";
            }
            else
            {
                dbresult.Password = Md5.Encrypt(password);
                repo.Update(dbresult);
                repo.Commit();
                result.IsSuccess     = true;
                result.MessageToUser = "******";
            }

            return(result);
        }
Exemplo n.º 19
0
        public VmGenericServiceResult Insert(VmCodeCategoryItem vmCodeCategoryItem)
        {
            VmGenericServiceResult result = new VmGenericServiceResult();

            try
            {
                CodeCategory r = new CodeCategory();

                Copy <VmCodeCategoryItem, CodeCategory>(vmCodeCategoryItem, r);

                if (r.CreatedBy.IsNullOrEmpty())
                {
                    r.CreatedBy = r.UpdatedBy = "System";
                }
                repo.Add(r);

                repo.Commit();

                result.IsSuccess = true;
            }
            catch (Exception e)
            {
                result.IsSuccess = false;
                var repoEntity = repo.Get(vmCodeCategoryItem.Id);
                if (repoEntity != null)
                {
                    Exception ee = new Exception("Id is already existed!");

                    result.Error = ee;
                }
                else
                {
                    result.Error = e;
                }
            }

            return(result);
        }
Exemplo n.º 20
0
        public async Task <VmGenericServiceResult> ResetPass(string username, string password)
        {
            var    result      = new VmGenericServiceResult();
            string newPassword = Md5.Encrypt(password);

            username = Md5.Decrypt(username);
            var dbresult = await repo.GetUserByUserName(username);

            if (dbresult == null)
            {
                result.IsSuccess     = false;
                result.MessageToUser = "******";
            }
            else
            {
                dbresult.Password = newPassword;
                repo.Update(dbresult);
                repo.Commit();
                result.IsSuccess     = true;
                result.MessageToUser = "******";
            }

            return(result);
        }
Exemplo n.º 21
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);
        }
Exemplo n.º 22
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);
        }