示例#1
0
        public IActionResult IsCompleteProfile()
        {
            var userId          = Convert.ToInt32(userManager.GetUserId(User));
            var applicationUser = unitOfWork.GetRepository <ApplicationUser>().Get(s => s.Id == userId).FirstOrDefault();

            if (applicationUser == null)
            {
                throw new UserNotExistsException(localizerAccount["UserNotFound"]);
            }

            bool isComplete = false;

            if (applicationUser.IsCompleteProfile)
            {
                isComplete = true;
            }

            var obj = new
            {
                IsCompelete = isComplete,
                UserType    = applicationUser.RoleId,
            };

            return(ApiResponder.RespondSuccessTo(HttpStatusCode.Ok, obj));
        }
示例#2
0
        public async Task <IActionResult> ResetPassword(string email, string newPassword, int pinCode)
        {
            User currentUser = await userManager.FindByEmailAsync(email);

            if (currentUser == null)
            {
                throw new UserNotExistsException(Account.UsetNotFound);
            }

            if (currentUser.PinCode != pinCode)
            {
                throw new InvalidPinCodeException(Account.InvalidPinCode);
            }

            if (currentUser.PinCodeExpiration < DateTime.UtcNow)
            {
                throw new PinCodeExpiredException(Account.PinCodeExpired);
            }

            IdentityResult deletePasswordResult = await userManager.RemovePasswordAsync(currentUser);

            if (!deletePasswordResult.Succeeded)
            {
                throw new IdentityException(deletePasswordResult.Errors.FirstOrDefault().Description);
            }

            IdentityResult addPasswordResult = await userManager.AddPasswordAsync(currentUser, newPassword);

            if (!addPasswordResult.Succeeded)
            {
                throw new IdentityException(addPasswordResult.Errors.FirstOrDefault().Description);
            }

            return(ApiResponder.RespondSuccessTo(HttpStatusCode.Ok, "Update new password sucessfully"));
        }
示例#3
0
        public IActionResult NormalFilter([FromBody] NormalFilterBindModel normalfileModel)
        {
            var  factoriesReturn  = new List <FactoryBriefReturnModel>();
            bool isEnableFavorite = false;
            Expression <Func <Profile, bool> > filter;
            var userId = Convert.ToInt32(userManager.GetUserId(User));

            if (userId != 0)
            {
                isEnableFavorite = true;
            }

            filter = s0 => (s0.CompanyName.ToLower().Contains(normalfileModel.Key.ToLower()) ||
                            s0.ProfileScopeBusiness.Any(r => normalfileModel.ScopeBusinesses.Contains(r.ScopeBusinessId)) ||
                            normalfileModel.CityId.Contains(s0.CityId))

                     || (s0.ProfileScopeBusiness.Any(r => r.ScopeBusiness.NameVI.ToLower().Contains(normalfileModel.Key.ToLower()) || r.ScopeBusiness.NameEN.ToLower().Contains(normalfileModel.Key.ToLower())) ||
                         s0.ProfileScopeBusiness.Any(r => normalfileModel.ScopeBusinesses.Contains(r.ScopeBusinessId)) ||
                         normalfileModel.CityId.Contains(s0.CityId));


            var resultNumber    = unitOfWork.GetContext().Profile.Where(filter).Count();
            var profileFavorite = unitOfWork.GetRepository <ProfileFavorite>().Get(s => s.ApplicationUserId == userId).ToList();
            var factories       = unitOfWork.GetRepository <Profile>().Get(filter, null, "ProfileScopeBusiness.ScopeBusiness").Skip((normalfileModel.Page - 1) * normalfileModel.PageSize).Take(normalfileModel.PageSize).ToList();

            foreach (var item in factories)
            {
                var factoryBriefReturn = new FactoryBriefReturnModel()
                {
                    Id           = item.Id,
                    Name         = item.CompanyName,
                    LocationName = item.Address,
                    IsFavorite   = profileFavorite.Any(s => s.ApplicationUserId == userId && s.ProfileId == item.Id) ? true : false,
                };
                factoryBriefReturn.ScopeBusiness = new List <string>();
                foreach (var itemScopeBusiness in item.ProfileScopeBusiness)
                {
                    if (HeaderLanguage() == "en-US")
                    {
                        factoryBriefReturn.ScopeBusiness.Add(itemScopeBusiness.ScopeBusiness.NameEN);
                    }
                    else if (HeaderLanguage() == "vi")
                    {
                        factoryBriefReturn.ScopeBusiness.Add(itemScopeBusiness.ScopeBusiness.NameVI);
                    }
                }

                factoriesReturn.Add(factoryBriefReturn);
            }


            var factoriesObjectReturn = new
            {
                ResultNumber     = resultNumber,
                Factories        = factoriesReturn,
                IsEnableFavorite = isEnableFavorite,
            };

            return(ApiResponder.RespondSuccessTo(HttpStatusCode.Ok, factoriesObjectReturn));
        }
示例#4
0
        public async Task <IActionResult> TestPushMessage(string deviceToken)
        {
            try
            {
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri("https://onesignal.com");
                    client.DefaultRequestHeaders.Add("authorization", "Basic NDBmZWQyZDktNDIwZi00NWMxLWEzZWQtODUzMGMxNzhhM2Ez");

                    var obj = new
                    {
                        app_id             = "e97913c0-0f01-4bac-8fc0-4fecfb87d8f2",
                        contents           = new { en = "Duc Nguyen" + ": " + "Ich nhau nhe" },
                        data               = new { userid = 1 },
                        include_player_ids = new string[] { deviceToken }
                    };

                    var jsonPost = JsonConvert.SerializeObject(obj);

                    var content = new StringContent(jsonPost, Encoding.UTF8, "application/json");

                    var result = await client.PostAsync("/api/v1/notifications", content);

                    string resultContent = await result.Content.ReadAsStringAsync();

                    Console.WriteLine(resultContent);
                }

                return(ApiResponder.RespondSuccessTo(HttpStatusCode.Ok, "Push ok"));
            }
            catch (Exception ex)
            {
                return(ApiResponder.RespondSuccessTo(HttpStatusCode.Ok, "Push ok"));
            }
        }
示例#5
0
        public IActionResult City()
        {
            var language             = this.HeaderLanguage();
            var charterCapitalReturn = new List <CompanySizeReturnModel>();
            var charterCapital       = unitOfWork.GetRepository <City>().Get().ToList();

            if (language == "vi")
            {
                foreach (var item in charterCapital)
                {
                    var charterCapitalItemReturn = new CompanySizeReturnModel()
                    {
                        Id   = item.Id,
                        Name = item.Name,
                    };
                    charterCapitalReturn.Add(charterCapitalItemReturn);
                }
            }
            else if (language == "en-US")
            {
                foreach (var item in charterCapital)
                {
                    var companySizeItemReturn = new CompanySizeReturnModel()
                    {
                        Id   = item.Id,
                        Name = item.Name,
                    };
                    charterCapitalReturn.Add(companySizeItemReturn);
                }
            }
            return(ApiResponder.RespondSuccessTo(HttpStatusCode.Ok, charterCapitalReturn));
        }
示例#6
0
        public IActionResult ScopeBusiness()
        {
            var language             = this.HeaderLanguage();
            var scopeBusinesesReturn = new List <ScopeBusinessReturnModel>();
            var scopeBusinesses      = unitOfWork.GetRepository <ScopeBusiness>().Get().ToList();

            if (language == "vi")
            {
                foreach (var item in scopeBusinesses)
                {
                    var scopeBusinessItemReturn = new ScopeBusinessReturnModel()
                    {
                        Id   = item.Id,
                        Name = item.NameVI,
                    };
                    scopeBusinesesReturn.Add(scopeBusinessItemReturn);
                }
            }
            else if (language == "en-US")
            {
                foreach (var item in scopeBusinesses)
                {
                    var scopeBusinessItemReturn = new ScopeBusinessReturnModel()
                    {
                        Id   = item.Id,
                        Name = item.NameEN,
                    };
                    scopeBusinesesReturn.Add(scopeBusinessItemReturn);
                }
            }
            return(ApiResponder.RespondSuccessTo(HttpStatusCode.Ok, scopeBusinesesReturn));
        }
示例#7
0
        public async Task <IActionResult> ForgotPassword(string email)
        {
            User currentUser = await userManager.FindByEmailAsync(email);

            if (currentUser == null)
            {
                throw new UserNotExistsException(Account.UsetNotFound);
            }

            int pinCode = new Random().Next(100000, 999999);

            currentUser.PinCode           = pinCode;
            currentUser.PinCodeExpiration = DateTime.UtcNow.AddHours(PinCodeExpirationTime);

            IdentityResult updateUserResult = await userManager.UpdateAsync(currentUser);

            if (!updateUserResult.Succeeded)
            {
                throw new IdentityException(updateUserResult.Errors.FirstOrDefault().Description);
            }

            string message = System.IO.File.ReadAllText(@"./HtmlPages/Email.html");

            await emailSender.SendEmailAsync(email, "Pin Code Confirmation",
                                             String.Format(message, currentUser.UserName, pinCode.ToString()));

            return(ApiResponder.RespondSuccessTo(HttpStatusCode.Ok, "Please check your email to setup new password"));
        }
示例#8
0
        public async Task <IActionResult> UpdateBusinessProfile([FromBody] BusinessProfileBindModel businessModel)
        {
            using (var transaction = unitOfWork.GetContext().Database.BeginTransaction())
            {
                try
                {
                    var userId = Convert.ToInt32(userManager.GetUserId(User));

                    var businessProfile = new Profile()
                    {
                        ApplicationUserId = userId,
                        RoleId            = Enums.UserRole.Business,
                        FoundedYear       = businessModel.FoundedYear,
                        Vision            = businessModel.Vision,
                        Address           = businessModel.Address,
                        CompanyDesciption = businessModel.CompanyDesciption,
                        WebSite           = businessModel.WebSite,

                        EmailContact       = businessModel.EmailContact,
                        PhoneNumberContact = businessModel.PhoneNumberContact,
                        ProductDescription = businessModel.ProductDescription,
                        ProductRequirement = businessModel.ProductRequirement,
                        TotalProductNeeded = businessModel.TotalProductNeeded,
                        PriceId            = businessModel.PriceId,
                        Lat = businessModel.Lat,
                        Lng = businessModel.Lng,
                    };



                    var businessProfileAdded = await unitOfWork.GetRepository <Profile>().InsertAsync(businessProfile);

                    foreach (var item in businessModel.FocusIndustry)
                    {
                        var profileFocusIndustry = new ProfileFocusIndustry()
                        {
                            ProfileId       = businessProfileAdded.Id,
                            FocusIndustryId = item,
                        };
                        await unitOfWork.GetRepository <ProfileFocusIndustry>().InsertAsync(profileFocusIndustry);
                    }

                    // update user role

                    var applicationUser = unitOfWork.GetRepository <ApplicationUser>().Get(s => s.Id == userId).FirstOrDefault();
                    applicationUser.RoleId            = Enums.UserRole.Business;
                    applicationUser.IsCompleteProfile = true;
                    await unitOfWork.GetRepository <ApplicationUser>().UpdateAsync(applicationUser);

                    transaction.Commit();

                    return(ApiResponder.RespondSuccessTo(HttpStatusCode.Ok, "Updated Business Account"));
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    throw;
                }
            }
        }
示例#9
0
        public IActionResult BaseToByteArray(string input)
        {
            var input2 = ValidateBase64EncodedString(input);

            byte[] decodedBytes = Convert.FromBase64String(input2);

            return(ApiResponder.RespondSuccessTo(HttpStatusCode.Ok, "ok"));
        }
示例#10
0
        public async Task <IActionResult> UpdateFactoryProfile([FromBody] FactoryProfileBindModel factoryModel)
        {
            using (var transaction = unitOfWork.GetContext().Database.BeginTransaction())
            {
                try
                {
                    var userId = Convert.ToInt32(userManager.GetUserId(User));

                    var factoryProfile = new Profile()
                    {
                        ApplicationUserId    = userId,
                        RoleId               = Enums.UserRole.Factory,
                        CompanyName          = factoryModel.CompanyName,
                        TypicalProduct       = factoryModel.TypicalProduct,
                        Address              = factoryModel.Address,
                        FoundedYear          = factoryModel.FoundedYear,
                        CompanyDesciption    = factoryModel.CompanyDesciption,
                        WebSite              = factoryModel.WebSite,
                        EmailContact         = factoryModel.EmailContact,
                        PhoneNumberContact   = factoryModel.PhoneNumberContact,
                        CompanySizeId        = factoryModel.CompanySizeId,
                        CharterCapitalId     = factoryModel.CharterCapitalId,
                        ProductionCapacityId = factoryModel.ProductionCapacityId,
                        RevenueId            = factoryModel.RevenueId,
                        MarketId             = factoryModel.MarketId,
                        CityId               = factoryModel.CityId,
                        Lat = factoryModel.Lat,
                        Lng = factoryModel.Lng,
                    };

                    var businessProfileAdded = await unitOfWork.GetRepository <Profile>().InsertAsync(factoryProfile);

                    foreach (var item in factoryModel.ScopeBusinesses)
                    {
                        var profileScopeBuniness = new ProfileScopeBusiness()
                        {
                            ProfileId       = businessProfileAdded.Id,
                            ScopeBusinessId = item,
                        };
                        await unitOfWork.GetRepository <ProfileScopeBusiness>().InsertAsync(profileScopeBuniness);
                    }


                    var applicationUser = unitOfWork.GetRepository <ApplicationUser>().Get(s => s.Id == userId).FirstOrDefault();
                    applicationUser.RoleId            = Enums.UserRole.Factory;
                    applicationUser.IsCompleteProfile = true;

                    transaction.Commit();

                    return(ApiResponder.RespondSuccessTo(HttpStatusCode.Ok, "Updated Factory Profile"));
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    throw;
                }
            }
        }
示例#11
0
        public IActionResult ChatHistory(int userId, int page, int pageSize, int totalSkipItem)
        {
            var myUserId       = Convert.ToInt32(userManager.GetUserId(User));
            var messageHistory = unitOfWork.GetRepository <Message>().Get(s => (s.ApplicationUserId == myUserId && s.ReceiverId == userId) || (s.ApplicationUserId == userId && s.ReceiverId == myUserId)).OrderByDescending(s => s.Id).Skip(totalSkipItem + ((page - 1) * pageSize)).Take(pageSize).ToList();

            var messageFinal = messageHistory.OrderBy(s => s.Id);

            return(ApiResponder.RespondSuccessTo(HttpStatusCode.Ok, messageFinal));
        }
示例#12
0
        public async Task <IActionResult> InsertInstituteFlag(string flag)
        {
            var instituteFlag = new InstitudeFlag()
            {
                Flag = flag,
            };

            var institutes = await unitOfWork.GetRepository <InstitudeFlag>().InsertAsync(instituteFlag);

            return(ApiResponder.RespondSuccessTo(HttpStatusCode.Ok, institutes));
        }
示例#13
0
        public async Task <IActionResult> ActiveStatus(string name)
        {
            var activeStatus = new ActiveStatus()
            {
                Status = name,
            };

            await unitOfWork.GetRepository <ActiveStatus>().InsertAsync(activeStatus);

            return(ApiResponder.RespondSuccessTo(HttpStatusCode.Ok, "ADDED"));
        }
示例#14
0
        public async Task <IActionResult> EntryCountry(string name)
        {
            var countryItem = new Country()
            {
                Name = name,
            };

            await unitOfWork.GetRepository <Country>().InsertAsync(countryItem);

            return(ApiResponder.RespondSuccessTo(HttpStatusCode.Ok, "ADDED"));
        }
示例#15
0
        public async Task <IActionResult> InsertOrginerStatus(string status)
        {
            var currency = new OrganizerStatus()
            {
                Status = status,
            };

            var currencyInserted = await unitOfWork.GetRepository <OrganizerStatus>().InsertAsync(currency);

            return(ApiResponder.RespondSuccessTo(HttpStatusCode.Ok, currencyInserted));
        }
示例#16
0
        public async Task <IActionResult> InsertCourseType(string type)
        {
            var courseType = new CourseType()
            {
                Type = type,
            };

            var courseTypeInserted = await unitOfWork.GetRepository <CourseType>().InsertAsync(courseType);

            return(ApiResponder.RespondSuccessTo(HttpStatusCode.Ok, courseTypeInserted));
        }
示例#17
0
        public async Task <IActionResult> InsertCourseStatus(string status)
        {
            var courseStatus = new CourseStatus()
            {
                Status = status,
            };

            var courseStatusInserted = await unitOfWork.GetRepository <CourseStatus>().InsertAsync(courseStatus);

            return(ApiResponder.RespondSuccessTo(HttpStatusCode.Ok, courseStatusInserted));
        }
示例#18
0
        public async Task <IActionResult> InsertCourseLevel(string level)
        {
            var courseLevel = new CourseLevel()
            {
                Level = level,
            };

            var courseLevelInserted = await unitOfWork.GetRepository <CourseLevel>().InsertAsync(courseLevel);

            return(ApiResponder.RespondSuccessTo(HttpStatusCode.Ok, courseLevelInserted));
        }
示例#19
0
        public async Task <IActionResult> InsertCourseFlag(string flag)
        {
            var courseFlag = new CourseFlag()
            {
                Flag = flag,
            };

            var courseFlagInserted = await unitOfWork.GetRepository <CourseFlag>().InsertAsync(courseFlag);

            return(ApiResponder.RespondSuccessTo(HttpStatusCode.Ok, courseFlagInserted));
        }
示例#20
0
        public async Task <IActionResult> InsertInstituteStatus(string status)
        {
            var instituteStatus = new InstituteStatus()
            {
                Status = status,
            };

            var institutes = await unitOfWork.GetRepository <InstituteStatus>().InsertAsync(instituteStatus);

            return(ApiResponder.RespondSuccessTo(HttpStatusCode.Ok, institutes));
        }
示例#21
0
        public async Task <IActionResult> InsertInstituteType(string type)
        {
            var instituteType = new InstituteType()
            {
                Type = type,
            };

            var institutes = await unitOfWork.GetRepository <InstituteType>().InsertAsync(instituteType);

            return(ApiResponder.RespondSuccessTo(HttpStatusCode.Ok, institutes));
        }
示例#22
0
        public async Task <IActionResult> InsertCourseCategory(string category)
        {
            var courseCategory = new CourseCategory()
            {
                Category = category,
            };

            var courseCategoryInserted = await unitOfWork.GetRepository <CourseCategory>().InsertAsync(courseCategory);

            return(ApiResponder.RespondSuccessTo(HttpStatusCode.Ok, courseCategoryInserted));
        }