Exemplo n.º 1
0
        public async Task <IHttpActionResult> PostHelperService([FromBody] HelperServiceDTO helperServiceDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Helper helper = new Helper
            {
                UserId        = helperServiceDTO.UserId,
                Experience    = helperServiceDTO.ExperienceYears,
                MaxAgeGroup   = helperServiceDTO.MaxAge,
                MinAgeGroup   = helperServiceDTO.MinAge,
                Qualification = helperServiceDTO.Qualification,
                RowStatus     = "I",
                Status        = true,
                CreatedDate   = DateTime.UtcNow
            };

            try
            {
                var result = await services.AddHelperAsync(helper);

                var helperId = result.HelperId;

                HelperService helperService = null;
                foreach (var item in helperServiceDTO.Service)
                {
                    int LocationId = 0;
                    if (!String.IsNullOrEmpty(item.Latitude) && !String.IsNullOrEmpty(item.Longitude))
                    {
                        DbGeography geography = LocationPoint.CreatePoint(Convert.ToInt64(item.Latitude), Convert.ToInt64(item.Longitude));
                        Location1   location  = new Location1
                        {
                            LocationName      = item.LocationName,
                            LocationGeography = geography,
                            RowStatus         = "I",
                            CreatedDate       = DateTime.UtcNow
                        };

                        var locationResult = await utilityServices.AddLocationAsync(location);

                        LocationId = locationResult.LocationId;
                    }

                    helperService = new HelperService
                    {
                        HelperId      = helperId,
                        HourPrice     = item.Hour,
                        MaxDayPrice   = item.MaxDayPrice,
                        MaxHourPrice  = item.MaxPriceHour,
                        MaxMonthPrice = item.MaxMonthPrice,
                        MinDayPrice   = item.MinDayPrice,
                        MinHourPrice  = item.MinPriceHour,
                        MinMonthPrice = item.MinMonthPrice,
                        MonthlyPrice  = item.Month,
                        RowStatus     = "I",
                        ServiceId     = item.ServiceId,
                        Status        = true,
                        CreatedDate   = DateTime.UtcNow
                    };

                    var serviceResult = await services.AddHelperServiceAsync(helperService);

                    int ServiceId = serviceResult.HelperServiceId;

                    if (item.Scopes.Count != 0)
                    {
                        HelperServiceScope serviceScope = null;
                        foreach (var scope in item.Scopes)
                        {
                            serviceScope = new HelperServiceScope
                            {
                                HelperServiceId = ServiceId,
                                HelperScopeId   = scope.ScopeId,
                                RowStatus       = "I",
                                CreatedDate     = DateTime.UtcNow
                            };
                            var scopResult = await services.AddHelperServiceScopeAsync(serviceScope);
                        }
                    }
                }
            }
            catch (DbUpdateException)
            {
                if (HelperServiceExists(helper.HelperId))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(Ok());
        }
Exemplo n.º 2
0
        public async Task <IHttpActionResult> Manage(int id, UserDTO userDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Locations location = new Locations();
            var       user     = new ApplicationUser();

            //string profileImage = string.Empty;

            user = await UserManager.FindByIdAsync(id);

            if (!string.IsNullOrEmpty(userDTO.ProfileImage))
            {
                string ImageName = FileConverter.UploadFileToFileFolder(userDTO.ProfileImage, "ProfileImages");
                user.ProfileImage = ImageName;
            }

            //if (string.IsNullOrEmpty(userDTO.ProfileImage))
            //{
            //    profileImage = FileConverter.UploadFileToFileFolder(userDTO.ProfileImage, "ProfileImages");
            //}
            if (!String.IsNullOrEmpty(userDTO.UserName))
            {
                user.UserName = userDTO.UserName;
            }

            user.GenderId = userDTO.GenderId;

            if (!String.IsNullOrEmpty(userDTO.MobileNumber))
            {
                user.PhoneNumber = userDTO.MobileNumber;
            }

            if (!String.IsNullOrEmpty(userDTO.Email))
            {
                user.Email = userDTO.Email;
            }

            if (!String.IsNullOrEmpty(userDTO.Description))
            {
                user.Description = userDTO.Description;
            }

            //user.ProfileImage = profileImage;

            if (!String.IsNullOrEmpty(userDTO.Latitude) && !String.IsNullOrEmpty(userDTO.Longitude))
            {
                var point = LocationPoint.CreatePoint(Convert.ToDouble(userDTO.Latitude), Convert.ToDouble(userDTO.Longitude));
                location.LocationName      = userDTO.LocationName;
                location.LocationGeography = point;
                location.RowStatus         = true;
                location.CreatedDate       = DateTime.UtcNow;
            }

            Locations rs;
            bool      locationAvailable = ExtentionMethods.IsLocationAvalable(location.LocationName);

            if (locationAvailable != false)
            {
                rs = await ExtentionMethods.AddLocationAsync(location);

                user.LocationId = rs.LocationId;
            }
            else
            {
                rs = ExtentionMethods.FindLocationAsync(location.LocationName);
                if (rs != null)
                {
                    user.LocationId = rs.LocationId;
                }
            }

            IdentityResult result = await UserManager.UpdateAsync(user);

            if (result.Succeeded)
            {
                return(Ok(new { Code = "200", Message = "Registration Successfully ", ID = user.Id }));
            }

            if (!result.Succeeded)
            {
                return(GetErrorResult(result));
            }

            return(Ok());
        }
Exemplo n.º 3
0
        public async Task <IHttpActionResult> PostJob([FromBody] JobDTO jobDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Job job = new Job();

            try
            {
                DbGeography geography = null;

                if (!String.IsNullOrEmpty(jobDTO.Latitude) && !String.IsNullOrEmpty(jobDTO.Longitude))
                {
                    double lat   = Convert.ToDouble(jobDTO.Latitude);
                    double longi = Convert.ToDouble(jobDTO.Longitude);
                    geography = LocationPoint.CreatePoint(lat, longi);
                }
                job.JobLocation = new JobLocation();
                job.JobPrice    = new JobPrice();
                job.JobTime     = new JobTime();

                job.CreatedUserId                    = Convert.ToInt32(jobDTO.UserId);
                job.JobTiltle                        = jobDTO.JobTitle;
                job.HelperType                       = jobDTO.HelperType;
                job.JobDescription                   = jobDTO.JobDescription;
                job.JobLocation.CreatedDate          = DateTime.UtcNow;
                job.JobLocation.JobLocationGeography = geography;
                job.JobLocation.JobLocationName      = jobDTO.LocationName;
                job.JobLocation.RowStatus            = "I";
                job.JobPrice.CreatedDate             = DateTime.UtcNow;
                job.JobPrice.Daily                   = jobDTO.IsDaily;
                job.JobPrice.Hourly                  = jobDTO.IsHourly;
                job.JobPrice.MaxPrice                = Convert.ToDecimal(jobDTO.MaxPrice);
                job.JobPrice.MinPrice                = Convert.ToDecimal(jobDTO.MinPrice);
                job.JobPrice.Monthly                 = jobDTO.IsMonthly;
                job.JobPrice.RowStatus               = "I";
                job.JobTime.CreatedDate              = DateTime.UtcNow;
                job.JobTime.EndTime                  = TimeSpan.Parse(jobDTO.EndTime);
                job.JobTime.Friday                   = jobDTO.IsFriday;
                job.JobTime.Monday                   = jobDTO.IsMonday;
                job.JobTime.Saturday                 = jobDTO.IsSaturday;
                job.JobTime.StartTime                = TimeSpan.Parse(jobDTO.StartTime);
                job.JobTime.Sunday                   = jobDTO.IsSunday;
                job.JobTime.Thursday                 = jobDTO.IsThursday;
                job.JobTime.Tuesday                  = jobDTO.IsTuesday;
                job.JobTime.Wednesday                = jobDTO.IsWednesday;
                job.JobType = jobDTO.JobType;

                var result = await jobServices.AddJobAsync(job);

                int JobId = result.JobId;

                if (jobDTO.JobServices.Count > 0)
                {
                    JobService jobService = null;

                    foreach (var item in jobDTO.JobServices)
                    {
                        jobService = new JobService
                        {
                            JobId     = JobId,
                            ServiceId = Convert.ToInt32(item.ServiceId)
                        };
                        var result1 = await jobServices.AddJobServiceAsync(jobService);

                        int JobServiceId = result1.JobServiceId;

                        if (JobServiceId > 0)
                        {
                            if (jobDTO.JobScope.Count > 0)
                            {
                                JobScope jobScope = null;

                                foreach (var scopeItem in jobDTO.JobScope)
                                {
                                    jobScope = new JobScope();
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }

            return(Ok(job.JobId));
        }