public ActionResult RegisterCarService(CreateCarServiceBm bm)
        {
            if (!this.ModelState.IsValid)
            {
                this.Response.StatusCode = 400;
                return(this.View("_Custom400BadRequestError"));
            }

            bm.ServerPath = this.Server.MapPath(CRRConfig.CarRepaitReportJson);

            var result = this.myUserManager.RegisterVehicleService(bm, this.GetAppUserId);

            if (result != null)
            {
                this.Response.StatusCode = 500;
                return(this.View("_Custom500InternalServerError"));
            }

            return(this.RedirectToAction("UserProfile"));
        }
Ejemplo n.º 2
0
        public ResultDto RegisterVehicleService(CreateCarServiceBm bm, string appUserId)
        {
            bool isUniqueName = this.vehicleService.IsServiceNameUnique(bm.Name);

            if (!isUniqueName)
            {
                return(new ResultDto("Already exists service with that name!"));
            }

            var address = this.addressService.GenerateAddress(bm.Country, bm.City, string.Empty, bm.StreetName, appUserId, true, AddressType.Work);

            var workingDays    = string.Empty;
            var nonWorkingDays = string.Empty;

            foreach (var wDay in bm.WorkingDays)
            {
                if (wDay.IsChecked)
                {
                    workingDays += wDay.StringValue + ", ";
                }
                else
                {
                    nonWorkingDays += wDay.StringValue + ", ";
                }
            }

            workingDays    = workingDays.Trim(' ').Trim(',');
            nonWorkingDays = nonWorkingDays.Trim(' ').Trim(',');

            var vehicleService = new VehicleService()
            {
                Name        = bm.Name.ToLower(),
                Address     = address,
                AddressId   = address.Id,
                Description = bm.Description,
                //LogoUrl = bm.logo
                WorkingTime    = "{0}: " + bm.StartWorkingTime + " {1}: " + bm.EndWorkingTime,
                WorkingDays    = workingDays,
                NonWorkingDays = nonWorkingDays
            };

            if (this.CanUploadImage(bm.Image))
            {
                var newImgUrl = this.GetDownloadbleLink(bm.Image, bm.ServerPath);

                vehicleService.LogoUrl = newImgUrl;
            }

            var user = this.userService.GetUserByAppId(appUserId);

            user.IsVehicleServiceOwner = true;
            user.VehicleService        = vehicleService;
            vehicleService.ServiceMembers.Add(user);

            var isAdded = this.vehicleService.AddVehicleService(vehicleService);

            if (!isAdded)
            {
                return(new ResultDto("Something goes wrong!"));
            }

            return(null);
        }