Beispiel #1
0
        public async Task <ActionResult> AddJobs_PartialView(JobViewModel job, ImageModelView userImage)
        {
            string success = null;

            bool isLookAuKwat = false;
            bool isParticuler = false;
            bool isPromotion  = false;

            if (User.IsInRole(MyRoleConstant.RoleAdmin) || (User.IsInRole(MyRoleConstant.Role_SuperAgent)))
            {
                isLookAuKwat = true;
                isPromotion  = true;
            }
            else
            {
                isParticuler = true;
            }

            if (job.Stock == 0)
            {
                job.Stock = 1;
            }
            JobModel model = new JobModel()
            {
                id             = job.id,
                Title          = job.Title,
                Description    = job.Description,
                TypeContract   = job.TypeContract,
                Town           = job.Town,
                Price          = job.Price,
                Street         = job.Street,
                ActivitySector = job.ActivitySector,
                DateAdd        = DateTime.UtcNow,
                SearchOrAskJob = job.SearchOrAskJob,
                IsActive       = true,
                IsLookaukwat   = isLookAuKwat,
                IsParticulier  = isParticuler,
                IsPromotion    = isPromotion,
                Provider_Id    = job.Provider_Id,
                Stock_Initial  = job.Stock,
                Stock          = job.Stock,
                ProductCountry = job.ProductCountry,
            };


            if (ModelState.IsValid)
            {
                using (var httpClient = new HttpClient())
                {
                    string          userId = User.Identity.GetUserId();
                    ApplicationUser user   = dal.GetUserByStrId(userId);

                    var fullAddress = $"{ model.Street /*+ model.Town + "," + ",Cameroon"*/}";
                    var response    = await httpClient.GetAsync("https://api.opencagedata.com/geocode/v1/json?q=" + fullAddress + "&key=a196040df44a4a41a471173aed07635c");

                    if (response.IsSuccessStatusCode)
                    {
                        var jsonn = await response.Content.ReadAsStringAsync();

                        var joo  = JObject.Parse(jsonn);
                        var latt = (string)joo["results"][0]["geometry"]["lat"];
                        var lonn = (string)joo["results"][0]["geometry"]["lng"];

                        List <ImageProcductModel> images = ImageAdd(userImage);

                        model.Images   = images;
                        model.User     = user;
                        model.Category = new CategoryModel {
                            CategoryName = "Emploi"
                        };
                        dal.AddJob(model, latt, lonn);
                        //check if email or phone is confirm and update date of publish announce for agent pay
                        if ((user.EmailConfirmed == true || user.PhoneNumberConfirmed == true) && user.Date_First_Publish == null)
                        {
                            dal.Update_Date_First_Publish(user);
                        }

                        return(RedirectToAction("AddImage", new { id = model.id }));
                        // return RedirectToAction("GetListProductByUser_PartialView", "User");
                    }
                }
            }
            success = "Désolé une erreur s'est produite!";
            return(RedirectToAction("UserProfile", "Home", new { message = success }));
        }