public ActionResult Create(CreateAppViewModel request)
        {
            Uri  uriResult;
            bool result = Uri.TryCreate(request.AppUrl, UriKind.Absolute, out uriResult) &&
                          (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps);

            if (result == false)
            {
                var ub = new UriBuilder(request.AppUrl);
                ub.Scheme      = "http";
                request.AppUrl = ub.Uri.AbsoluteUri;
            }

            if (result == false)
            {
                return(BadRequest());
            }

            _unitOfWork.Repository <Application>().Insert(new Application()
            {
                Name = _htmlEncoder.Encode(request.AppName),
                Url  = _htmlEncoder.Encode(request.AppUrl),
                RequestIntervalAtMinute = request.AppRequestIntervalAtMinute,
                UserId = User.FindFirst(ClaimTypes.NameIdentifier).Value,
            });
            _unitOfWork.Save();

            return(Ok());
        }
Example #2
0
        public async Task <IActionResult> CreateApp(CreateAppViewModel model)
        {
            var cuser = await GetCurrentUserAsync();

            if (!ModelState.IsValid)
            {
                model.ModelStateValid = false;
                model.RootRecover(cuser, 1);
                return(View(model));
            }
            var newApp = new App(model.AppName, model.AppDescription, model.AppCategory, model.AppPlatform)
            {
                CreatorId = cuser.Id
            };

            // Default icon
            if (Request.Form.Files.Count == 0 || Request.Form.Files.First().Length < 1)
            {
                newApp.IconPath = $"{_configuration["AppsIconSiteName"]}/appdefaulticon.png";
            }
            else
            {
                var probeFile = await _storageService.SaveToProbe(Request.Form.Files.First(), _configuration["AppsIconSiteName"], newApp.AppId, SaveFileOptions.RandomName);

                newApp.IconPath = $"{probeFile.SiteName}/{probeFile.FilePath}";
            }
            _dbContext.Apps.Add(newApp);
            await _dbContext.SaveChangesAsync();

            return(RedirectToAction(nameof(ViewApp), new { id = newApp.AppId }));
        }
Example #3
0
        public async Task <IActionResult> CreateApp(CreateAppViewModel model)
        {
            var cuser = await GetCurrentUserAsync();

            if (!ModelState.IsValid)
            {
                model.ModelStateValid = false;
                model.Recover(cuser, 1);
                return(View(model));
            }
            string iconPath = string.Empty;

            if (Request.Form.Files.Count == 0 || Request.Form.Files.First().Length < 1)
            {
                iconPath = Values.DeveloperServerAddress + "/images/appdefaulticon.png";
            }
            else
            {
                iconPath = await StorageService.SaveToOSS(Request.Form.Files.First(), Values.AppsIconBucketId, 365);
            }

            var _newApp = new App(cuser.Id, model.AppName, model.AppDescription, model.AppCategory, model.AppPlatform)
            {
                CreaterId      = cuser.Id,
                AppIconAddress = iconPath
            };

            _dbContext.Apps.Add(_newApp);
            await _dbContext.SaveChangesAsync();

            return(RedirectToAction(nameof(ViewApp), new { id = _newApp.AppId }));
        }
Example #4
0
        public async Task <IActionResult> CreateApp(CreateAppViewModel model)
        {
            var cuser = await GetCurrentUserAsync();

            if (!ModelState.IsValid)
            {
                model.ModelStateValid = false;
                model.Recover(cuser, 1);
                return(View(model));
            }
            string iconPath = string.Empty;

            if (Request.Form.Files.Count == 0 || Request.Form.Files.First().Length < 1)
            {
                iconPath = $"{_serviceLocation.CDN}/images/appdefaulticon.png";
            }
            else
            {
                var ossFile = await _storageService.SaveToOSS(Request.Form.Files.First(), Convert.ToInt32(_configuration["AppsIconBucketId"]), 3000);

                iconPath = ossFile.Path;
            }

            var _newApp = new App(model.AppName, model.AppDescription, model.AppCategory, model.AppPlatform)
            {
                CreatorId      = cuser.Id,
                AppIconAddress = iconPath
            };

            _dbContext.Apps.Add(_newApp);
            await _dbContext.SaveChangesAsync();

            return(RedirectToAction(nameof(ViewApp), new { id = _newApp.AppId }));
        }
        public async Task <IActionResult> CreateApp(string storeId, CreateAppViewModel vm)
        {
            var store = GetCurrentStore();

            vm.StoreId = store.Id;

            if (!Enum.TryParse(vm.SelectedAppType, out AppType appType))
            {
                ModelState.AddModelError(nameof(vm.SelectedAppType), "Invalid App Type");
            }

            if (!ModelState.IsValid)
            {
                return(View(vm));
            }

            var appData = new AppData
            {
                StoreDataId = store.Id,
                Name        = vm.AppName,
                AppType     = appType.ToString()
            };

            var defaultCurrency = await GetStoreDefaultCurrentIfEmpty(appData.StoreDataId, null);

            switch (appType)
            {
            case AppType.Crowdfund:
                var emptyCrowdfund = new CrowdfundSettings {
                    TargetCurrency = defaultCurrency
                };
                appData.SetSettings(emptyCrowdfund);
                break;

            case AppType.PointOfSale:
                var empty = new PointOfSaleSettings {
                    Currency = defaultCurrency
                };
                appData.SetSettings(empty);
                break;
            }

            await _appService.UpdateOrCreateApp(appData);

            TempData[WellKnownTempData.SuccessMessage] = "App successfully created";
            CreatedAppId = appData.Id;

            switch (appType)
            {
            case AppType.PointOfSale:
                return(RedirectToAction(nameof(UpdatePointOfSale), new { appId = appData.Id }));

            case AppType.Crowdfund:
                return(RedirectToAction(nameof(UpdateCrowdfund), new { appId = appData.Id }));

            default:
                return(RedirectToAction(nameof(ListApps), new { storeId = appData.StoreDataId }));
            }
        }
Example #6
0
        public async Task <IActionResult> CreateApp()
        {
            var cuser = await GetCurrentUserAsync();

            var model = new CreateAppViewModel(cuser);

            return(View(model));
        }
Example #7
0
        public async Task <IActionResult> CreateApp(CreateAppViewModel vm)
        {
            var stores = await _AppsHelper.GetOwnedStores(GetUserId());

            if (stores.Length == 0)
            {
                StatusMessage = "Error: You must own at least one store";
                return(RedirectToAction(nameof(ListApps)));
            }
            var selectedStore = vm.SelectedStore;

            vm.SetStores(stores);
            vm.SelectedStore = selectedStore;

            if (!Enum.TryParse <AppType>(vm.SelectedAppType, out AppType appType))
            {
                ModelState.AddModelError(nameof(vm.SelectedAppType), "Invalid App Type");
            }

            if (!ModelState.IsValid)
            {
                return(View(vm));
            }

            if (!stores.Any(s => s.Id == selectedStore))
            {
                StatusMessage = "Error: You are not owner of this store";
                return(RedirectToAction(nameof(ListApps)));
            }
            var id = Encoders.Base58.EncodeData(RandomUtils.GetBytes(20));

            using (var ctx = _ContextFactory.CreateContext())
            {
                var appData = new AppData()
                {
                    Id = id
                };
                appData.StoreDataId = selectedStore;
                appData.Name        = vm.Name;
                appData.AppType     = appType.ToString();
                ctx.Apps.Add(appData);
                await ctx.SaveChangesAsync();
            }
            StatusMessage = "App successfully created";
            CreatedAppId  = id;

            switch (appType)
            {
            case AppType.PointOfSale:
                return(RedirectToAction(nameof(UpdatePointOfSale), new { appId = id }));

            case AppType.Crowdfund:
                return(RedirectToAction(nameof(UpdateCrowdfund), new { appId = id }));

            default:
                return(RedirectToAction(nameof(ListApps)));
            }
        }
Example #8
0
        public async Task <IActionResult> CreateApp(CreateAppViewModel vm)
        {
            var stores = await _AppService.GetOwnedStores(GetUserId());

            if (stores.Length == 0)
            {
                TempData.SetStatusMessageModel(new StatusMessageModel()
                {
                    Html =
                        $"Error: You need to create at least one store. <a href='{(Url.Action("CreateStore", "UserStores"))}' class='alert-link'>Create store</a>",
                    Severity = StatusMessageModel.StatusSeverity.Error
                });
                return(RedirectToAction(nameof(ListApps)));
            }
            var selectedStore = vm.SelectedStore;

            vm.SetStores(stores);
            vm.SelectedStore = selectedStore;

            if (!Enum.TryParse <AppType>(vm.SelectedAppType, out AppType appType))
            {
                ModelState.AddModelError(nameof(vm.SelectedAppType), "Invalid App Type");
            }

            if (!ModelState.IsValid)
            {
                return(View(vm));
            }

            if (!stores.Any(s => s.Id == selectedStore))
            {
                TempData[WellKnownTempData.ErrorMessage] = "You are not owner of this store";
                return(RedirectToAction(nameof(ListApps)));
            }
            var appData = new AppData
            {
                StoreDataId = selectedStore,
                Name        = vm.Name,
                AppType     = appType.ToString()
            };
            await _AppService.UpdateOrCreateApp(appData);

            TempData[WellKnownTempData.SuccessMessage] = "App successfully created";
            CreatedAppId = appData.Id;

            switch (appType)
            {
            case AppType.PointOfSale:
                return(RedirectToAction(nameof(UpdatePointOfSale), new { appId = appData.Id }));

            case AppType.Crowdfund:
                return(RedirectToAction(nameof(UpdateCrowdfund), new { appId = appData.Id }));

            default:
                return(RedirectToAction(nameof(ListApps)));
            }
        }
Example #9
0
        public ActionResult Index()
        {
            var model = new CreateAppViewModel()
            {
                ActionNo = 1
            };
            var districts = GetDistrictItems();

            ViewBag.DistrictId = new SelectList(districts, "ID", "Name", "RegionName", districts[0]);
            return(View(model));
        }
        public async Task <IActionResult> CreateApp()
        {
            var stores = await GetOwnedStores();

            if (stores.Length == 0)
            {
                StatusMessage = "Error: You must have created at least one store";
                return(RedirectToAction(nameof(ListApps)));
            }
            var vm = new CreateAppViewModel();

            vm.SetStores(stores);
            return(View(vm));
        }
Example #11
0
        public async Task <IActionResult> CreateApp(CreateAppViewModel model)
        {
            var _cuser = await GetCurrentUserAsync();

            var _newApp = new App(_cuser.Id, model.AppName, model.AppDescription, model.AppCategory, model.AppPlatform)
            {
                CreaterId = _cuser.Id
            };

            _dbContext.Apps.Add(_newApp);
            await _dbContext.SaveChangesAsync();

            return(RedirectToAction(nameof(AllApps)));
        }
Example #12
0
        public async Task <IActionResult> CreateApp(CreateAppViewModel model)
        {
            var _cuser = await GetCurrentUserAsync();

            if (!ModelState.IsValid)
            {
                model.ModelStateValid = false;
                model.Recover(_cuser, 1);
                return(View(model));
            }
            string iconPath = string.Empty;

            if (Request.Form.Files.Count == 0 || Request.Form.Files.First().Length < 1)
            {
                iconPath = Values.DeveloperServerAddress + "/images/appdefaulticon.png";
            }
            else
            {
                var    iconFile      = Request.Form.Files.First();
                string DirectoryPath = GetCurrentDirectory() + DirectorySeparatorChar + $@"Storage" + DirectorySeparatorChar;
                if (Exists(DirectoryPath) == false)
                {
                    CreateDirectory(DirectoryPath);
                }
                var NewFilePath = DirectoryPath + StringOperation.RandomString(10) + GetExtension(iconFile.FileName);
                var fileStream  = new FileStream(NewFilePath, FileMode.Create);
                await iconFile.CopyToAsync(fileStream);

                fileStream.Close();
                var fileAddress = await ApiService.UploadFile(await AppsContainer.AccessToken()(), Values.AppsIconBucketId, NewFilePath);

                iconPath = fileAddress.Path;
            }

            var _newApp = new App(_cuser.Id, model.AppName, model.AppDescription, model.AppCategory, model.AppPlatform)
            {
                CreaterId      = _cuser.Id,
                AppIconAddress = iconPath
            };

            _dbContext.Apps.Add(_newApp);
            await _dbContext.SaveChangesAsync();

            return(RedirectToAction(nameof(ViewApp), new { id = _newApp.AppId }));
        }
Example #13
0
        public async Task <IActionResult> CreateApp()
        {
            var stores = await _AppService.GetOwnedStores(GetUserId());

            if (stores.Length == 0)
            {
                TempData.SetStatusMessageModel(new StatusMessageModel()
                {
                    Html =
                        $"Error: You need to create at least one store. <a href='{(Url.Action("CreateStore", "UserStores"))}' class='alert-link'>Create store</a>",
                    Severity = StatusMessageModel.StatusSeverity.Error
                });
                return(RedirectToAction(nameof(ListApps)));
            }
            var vm = new CreateAppViewModel();

            vm.SetStores(stores);
            return(View(vm));
        }
Example #14
0
        public async Task <IActionResult> CreateApp(CreateAppViewModel model)
        {
            var currentUser = await GetCurrentUserAsync();

            if (!ModelState.IsValid)
            {
                model.RootRecover(currentUser);
                return(View(model));
            }
            var newApp = new DeveloperApp(model.AppName, model.AppDescription, model.AppCategory, model.AppPlatform, model.IconPath)
            {
                CreatorId = currentUser.Id
            };
            await _dbContext.Apps.AddAsync(newApp);

            await _dbContext.SaveChangesAsync();

            return(RedirectToAction(nameof(ViewApp), new { id = newApp.AppId }));
        }
Example #15
0
        public async Task <IActionResult> CreateApp()
        {
            var stores = await _AppService.GetOwnedStores(GetUserId());

            if (stores.Length == 0)
            {
                StatusMessage = new StatusMessageModel()
                {
                    Html =
                        $"Error: Necesitas crear al menos una tienda.. <a href='{(Url.Action("CreateStore", "UserStores"))}'>Crear tienda</a>",
                    Severity = StatusMessageModel.StatusSeverity.Error
                }.ToString();
                return(RedirectToAction(nameof(ListApps)));
            }
            var vm = new CreateAppViewModel();

            vm.SetStores(stores);
            return(View(vm));
        }
        public async Task <IActionResult> CreateApp()
        {
            var stores = await _AppsHelper.GetOwnedStores(GetUserId());

            if (stores.Length == 0)
            {
                StatusMessage = new StatusMessageModel()
                {
                    Html =
                        $"Error: You must have created at least one store. <a href='{(Url.Action("CreateStore", "UserStores"))}'>Create store</a>",
                    Severity = StatusMessageModel.StatusSeverity.Error
                }.ToString();
                return(RedirectToAction(nameof(ListApps)));
            }
            var vm = new CreateAppViewModel();

            vm.SetStores(stores);
            return(View(vm));
        }
        public void CreateShouldSaveNewApp()
        {
            // ARRANGE
            var model = new CreateAppViewModel();

            var logic = new Mock <IAppLogic>();

            logic
            .Setup(x => x.Create(It.IsAny <AppEntity>()))
            .Verifiable("Should create the app");

            var controller = new AppController(logic.Object);

            //ACT
            var result = controller.Create(model) as RedirectToRouteResult;

            //ASSERT
            logic.Verify();

            Assert.NotNull(result);
            Assert.AreEqual("Index", result.RouteValues["Action"]);
            Assert.AreEqual("App", result.RouteValues["Controller"]);
        }
Example #18
0
        public async Task <IActionResult> CreateApp(CreateAppViewModel vm)
        {
            var stores = await _AppService.GetOwnedStores(GetUserId());

            if (stores.Length == 0)
            {
                StatusMessage = new StatusMessageModel()
                {
                    Html =
                        $"Error: Necesitas crear al menos una tienda. <a href='{(Url.Action("CreateStore", "UserStores"))}'>Crear tienda</a>",
                    Severity = StatusMessageModel.StatusSeverity.Error
                }.ToString();
                return(RedirectToAction(nameof(ListApps)));
            }
            var selectedStore = vm.SelectedStore;

            vm.SetStores(stores);
            vm.SelectedStore = selectedStore;

            if (!Enum.TryParse <AppType>(vm.SelectedAppType, out AppType appType))
            {
                ModelState.AddModelError(nameof(vm.SelectedAppType), "Tipo de aplicación no válido");
            }

            if (!ModelState.IsValid)
            {
                return(View(vm));
            }

            if (!stores.Any(s => s.Id == selectedStore))
            {
                StatusMessage = "Error: No eres propietario de esta tienda.";
                return(RedirectToAction(nameof(ListApps)));
            }
            var id = Encoders.Base58.EncodeData(RandomUtils.GetBytes(20));

            using (var ctx = _ContextFactory.CreateContext())
            {
                var appData = new AppData()
                {
                    Id = id
                };
                appData.StoreDataId = selectedStore;
                appData.Name        = vm.Name;
                appData.AppType     = appType.ToString();
                ctx.Apps.Add(appData);
                await ctx.SaveChangesAsync();
            }
            StatusMessage = "Aplicación creada con éxito";
            CreatedAppId  = id;

            switch (appType)
            {
            case AppType.PointOfSale:
                return(RedirectToAction(nameof(UpdatePointOfSale), new { appId = id }));

            case AppType.Crowdfund:
                return(RedirectToAction(nameof(UpdateCrowdfund), new { appId = id }));

            default:
                return(RedirectToAction(nameof(ListApps)));
            }
        }
Example #19
0
        public ActionResult Index(CreateAppViewModel model)
        {
            var districts = GetDistrictItems();

            ViewBag.DistrictId = new SelectList(districts, "ID", "Name", "RegionName", model.DistrictId);
            if (string.IsNullOrEmpty(model.ApplicantPIN) || string.IsNullOrEmpty(model.PassportNo) || string.IsNullOrEmpty(model.PassportSeries))
            {
                ViewBag.Error = "Необходимо заполнить все поля";
                return(View(model));
            }

            if (SendRequest(new
            {
                clientId = "8d8461a4-9d3e-4136-98a7-66697078371d",
                orgName = "ПОРТАЛ-ГБД",
                request = new
                {
                    passportDataByPSN = new
                    {
                        request = new
                        {
                            pin = model.ApplicantPIN,
                            series = model.PassportSeries,
                            number = model.PassportNo
                        }
                    }
                }
            }, "http://localhost/ServiceConstructor/SoapClient/SendRequest2", "POST", out dynamic response, out string errorMessage))
            {
                if (response.response.passportDataByPSNResponse.response != null)
                {
                    var r = response.response.passportDataByPSNResponse.response;
                    model.passportPerson = ((JObject)r).ToObject <CreateAppViewModel._passportPerson>();
                }
                else
                {
                    //ViewBag.Error = "Данные о браке отсутствуют";
                }
            }

            if (SendRequest(new
            {
                clientId = "731537be-3e88-4f9a-8f2b-4aea6b5afc01",
                orgName = "ПОРТАЛ-ГБД",
                request = new {
                    zagsPinMarriageAct = new {
                        request = new {
                            pin = model.ApplicantPIN
                        }
                    }
                }
            }, "http://localhost/ServiceConstructor/SoapClient/SendRequest2", "POST", out response, out errorMessage))
            {
                if (response.response.zagsPinMarriageActResponse.response != null)
                {
                    var r = response.response.zagsPinMarriageActResponse.response;
                    model.zagsData = ((JObject)r).ToObject <CreateAppViewModel._zagsData>();
                }
                else
                {
                    //ViewBag.Error = "Данные о браке отсутствуют";
                }
            }
            else
            {
                ViewBag.Error = errorMessage;
            }

            if (model.ActionNo == 1)
            {
                model.ActionNo = 2;
            }
            else if (model.ActionNo == 2)
            {
                Models.ScriptExecutor.CreateCandidateApp(model);
                var msg = @"Ваше заявление успешно отправлено в {orgName} по адресу {address}. Вам необходимо проверять статус своего заявления в течении следующих 10 рабочих дней. Для дополнительной консультации можете обратиться по тел. {contact}";
                foreach (var el in XDocument.Load(System.Web.Hosting.HostingEnvironment.MapPath("~/Content/organizations.xml")).Root.Elements())
                {
                    var orgName  = el.Attribute("name").Value;
                    var newOrgId = Guid.Parse(el.Attribute("newOrgId").Value);
                    var address  = el.Attribute("address").Value;
                    var contact  = el.Attribute("contact").Value;
                    if (newOrgId == model.DistrictId)
                    {
                        msg = msg.Replace("{orgName}", orgName);
                        msg = msg.Replace("{address}", address);
                        msg = msg.Replace("{contact}", contact);
                        break;
                    }
                }
                ViewBag.Message = msg;
                //model = new CreateAppViewModel {ActionNo = 1 };
            }

            return(View(model));
        }