예제 #1
0
        public async Task <IActionResult> Create(SpecialTags specialTags)
        {
            // Check the State Model Binding
            if (ModelState.IsValid)
            {
                _colibriDbContext.Add(specialTags);
                await _colibriDbContext.SaveChangesAsync();

                // avoid Refreshing the POST Operation -> Redirect
                //return View("Details", newCategory);
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                // one can simply return to the Form View again for Correction
                return(View(specialTags));
            }
        }
예제 #2
0
        public async Task <IActionResult> Create(CategoryGroups categoryGroups)
        {
            // Check the State Model Binding
            if (ModelState.IsValid)
            {
                // Strings für TypeOfCategoryGroup schreiben
                if (categoryGroups.TypeOfCategoryGroup.Equals("0"))
                {
                    categoryGroups.TypeOfCategoryGroup = "Product";
                }
                else
                {
                    categoryGroups.TypeOfCategoryGroup = "Service";
                }

                _colibriDbContext.Add(categoryGroups);
                await _colibriDbContext.SaveChangesAsync();

                // Publish the Created Category
                using (var bus = RabbitHutch.CreateBus("host=localhost"))
                {
                    //bus.Publish(categoryGroups, "create_category_groups");
                    //await bus.PublishAsync("create_category_groups").ContinueWith(task =>
                    // {
                    //     if (task.IsCompleted && !task.IsFaulted)
                    //     {
                    //         Console.WriteLine("Task Completed");
                    //         Console.ReadLine();
                    //     }
                    // });
                    await bus.SendAsync("create_category_groups", categoryGroups);
                }


                // avoid Refreshing the POST Operation -> Redirect
                return(RedirectToAction(nameof(Index)));
                //return RedirectToAction("Index", "CategoryGroups", new { area = "Admin" });
            }
            else
            {
                // one can simply return to the Form View again for Correction
                return(View(categoryGroups));
            }
        }
예제 #3
0
        public async Task <IActionResult> createPost()
        {
            //// Security Claims
            System.Security.Claims.ClaimsPrincipal currentUser = this.User;

            //// Claims Identity
            var claimsIdentity = (ClaimsIdentity)this.User.Identity;
            var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);

            // Check the State Model Binding
            if (ModelState.IsValid)
            {
                // add a UserService first to retrieve it, so one can add User Service to it
                _colibriDbContext.Add(UserServicesAddToEntityViewModel.UserServices);
                await _colibriDbContext.SaveChangesAsync();

                // Image being saved
                // use the Hosting Environment
                string webRootPath = _hostingEnvironment.WebRootPath;

                // retrieve all Files (typed by the User in the View )
                var files = HttpContext.Request.Form.Files;

                // to update the User Service from the DB: retrieve the Db Files
                // new Properties will be added to the specific User Service -> Id needed!
                var userServicesFromDb = _colibriDbContext.UserServices.Find(UserServicesAddToEntityViewModel.UserServices.Id);

                // Image File has been uploaded from the View
                if (files.Count != 0)
                {
                    // Image has been uploaded
                    // the exact Location of the ImageFolderProduct for the Service
                    var uploads = Path.Combine(webRootPath, StaticDetails.ImageFolderService);

                    // find the Extension of the File
                    var extension = Path.GetExtension(files[0].FileName);

                    // use the FileStreamObject -> copy the File from the Uploaded to the Server
                    // create the File on the Server
                    using (var filestream = new FileStream(Path.Combine(uploads, UserServicesAddToEntityViewModel.UserServices.Id + extension), FileMode.Create))
                    {
                        files[0].CopyTo(filestream);
                    }

                    // ProductsImage = exact Path of the Image on the Server + ImageName + Extension
                    userServicesFromDb.Image = @"\" + StaticDetails.ImageFolderService + @"\" + UserServicesAddToEntityViewModel.UserServices.Id + extension;
                }
                // Image File has not been uploaded -> use a default one
                else
                {
                    // a DUMMY Image if the User does not have uploaded any File (default Image)
                    var uploads = Path.Combine(webRootPath, StaticDetails.ImageFolderService + @"\" + StaticDetails.DefaultServiceImage);

                    // copy the Image from the Server and rename it as the ProductImage ID
                    System.IO.File.Copy(uploads, webRootPath + @"\" + StaticDetails.ImageFolderService + @"\" + UserServicesAddToEntityViewModel.UserServices.Id + ".jpg");

                    // update the ProductFromDb.Image with the actual FileName
                    userServicesFromDb.Image = @"\" + StaticDetails.ImageFolderService + @"\" + UserServicesAddToEntityViewModel.UserServices.Id + ".jpg";
                }

                // add the current User as the Creator of the Advertisement
                userServicesFromDb.ApplicationUserId = claim.Value;

                // add the CreatedOn Property to the Model
                userServicesFromDb.CreatedOn = DateTime.Now;

                // save the Changes asynchronously
                // update the Image Part inside of the DB
                await _colibriDbContext.SaveChangesAsync();

                // Publish the Created Advertisement's Product
                using (var bus = RabbitHutch.CreateBus("host=localhost"))
                {
                    Console.WriteLine("Publishing an User Service Message.");
                    Console.WriteLine();

                    //bus.Publish<AdvertisementViewModel>(AdvertisementViewModel, "my_subscription_id");
                    //bus.Publish(productsFromDb, "my_subscription_id");

                    await bus.SendAsync("create_user_service", userServicesFromDb);
                }

                // TODO
                // Convert to JSON
                //var parsedJson = new JavaScriptSerializer().Serialize(ProductsViewModel);
                var result = Json(UserServicesAddToEntityViewModel);

                // avoid Refreshing the POST Operation -> Redirect
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                // one can simply return to the Form View again for Correction
                return(View(UserServicesAddToEntityViewModel));
            }
        }
예제 #4
0
        public async Task <IActionResult> CreatePost()
        {
            // Check the State Model Binding
            if (ModelState.IsValid)
            {
                //add a Product first to retrieve it, so one can add Properties to it
                _colibriDbContext.Add(ProductsViewModel.Products);
                await _colibriDbContext.SaveChangesAsync();

                // TODO save in the Search Entity
                //_colibriDbContext.Add(ProductsViewModel.CategoryTypes);
                //await _colibriDbContext.SaveChangesAsync();


                // Image being saved
                // use the Hosting Environment
                string webRootPath = _hostingEnvironment.WebRootPath;

                // retrieve all Files (typed by the User in the View )
                var files = HttpContext.Request.Form.Files;

                // to update the Products from the DB: retrieve the Db Files
                // new Properties will be added to the specific Product -> Id needed!
                var productsFromDb = _colibriDbContext.Products.Find(ProductsViewModel.Products.Id);

                // Image File has been uploaded from the View
                if (files.Count != 0)
                {
                    // Image has been uploaded
                    // the exact Location of the ImageFolderProduct
                    var uploads = Path.Combine(webRootPath, StaticDetails.ImageFolderProduct);

                    // find the Extension of the File
                    var extension = Path.GetExtension(files[0].FileName);

                    // use the FileStreamObject -> copy the File from the Uploaded to the Server
                    // create the File on the Server
                    using (var filestream = new FileStream(Path.Combine(uploads, ProductsViewModel.Products.Id + extension), FileMode.Create))
                    {
                        files[0].CopyTo(filestream);
                    }

                    // ProductsImage = exact Path of the Image on the Server + ImageName + Extension
                    productsFromDb.Image = @"\" + StaticDetails.ImageFolderProduct + @"\" + ProductsViewModel.Products.Id + extension;
                }
                // Image File has not been uploaded -> use a default one
                else
                {
                    // a DUMMY Image if the User does not have uploaded any File (default Image)
                    var uploads = Path.Combine(webRootPath, StaticDetails.ImageFolderProduct + @"\" + StaticDetails.DefaultProductImage);

                    // copy the Image from the Server and rename it as the ProductImage ID
                    System.IO.File.Copy(uploads, webRootPath + @"\" + StaticDetails.ImageFolderProduct + @"\" + ProductsViewModel.Products.Id + ".jpg");

                    // update the ProductFromDb.Image with the actual FileName
                    productsFromDb.Image = @"\" + StaticDetails.ImageFolderProduct + @"\" + ProductsViewModel.Products.Id + ".jpg";
                }

                // add the CreatedOn Property to the Model
                productsFromDb.CreatedOn = DateTime.Now;

                // save the Changes asynchronously
                // update the Image Part inside of the DB
                await _colibriDbContext.SaveChangesAsync();

                // Publish the Created Product
                //using (var bus = RabbitHutch.CreateBus("host=localhost"))
                //{
                //    //bus.Publish(categoryGroups, "create_category_groups");
                //    await bus.PublishAsync("create_product_by_admin").ContinueWith(task =>
                //    {
                //        if (task.IsCompleted && !task.IsFaulted)
                //        {
                //            Console.WriteLine("Task Completed");
                //            Console.ReadLine();
                //        }
                //    });
                //}

                using (var bus = RabbitHutch.CreateBus("host=localhost"))
                {
                    await bus.SendAsync("create_product_by_admin", productsFromDb);
                }


                // avoid Refreshing the POST Operation -> Redirect
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                // one can simply return to the Form View again for Correction
                return(View(ProductsViewModel));
            }
        }
예제 #5
0
        public async Task <IActionResult> Create(CategoryTypesAndCategoryGroupsViewModel model)
        {
            // i18n
            ViewData["CreateCategoryType"] = _localizer["CreateCategoryTypeText"];
            ViewData["Create"]             = _localizer["CreateText"];
            ViewData["BackToList"]         = _localizer["BackToListText"];
            ViewData["Name"] = _localizer["NameText"];

            // Check the State Model Binding
            if (ModelState.IsValid)
            {
                // check if CategoryTypes exists or not & check if Combination of CategoryTypes and CategoryGroup exists
                var doesCategoryTypesExist = _colibriDbContext.CategoryTypes.Where(s => s.Name == model.CategoryTypes.Name).Count();
                var doesCategoryTypesAndCategoryGroupsExist = _colibriDbContext.CategoryTypes.Where(s => s.Name == model.CategoryTypes.Name && s.CategoryGroupId == model.CategoryTypes.CategoryGroupId).Count();

                if (doesCategoryTypesExist > 0 && model.isNew)
                {
                    // error
                    StatusMessage = "Error : CategoryTypes Name already exists";
                }
                else
                {
                    if (doesCategoryTypesExist == 0 && !model.isNew)
                    {
                        // error
                        StatusMessage = "Error : CategoryTypes does not exist";
                    }
                    else
                    {
                        if (doesCategoryTypesAndCategoryGroupsExist > 0)
                        {
                            // error
                            StatusMessage = "Error : CategoryTypes and CategoryGroups combination already exists";
                        }
                        else
                        {
                            if (model.CategoryTypes.PLZ == null)
                            {
                                model.CategoryTypes.isGlobal = true;
                            }

                            // Wenn keine Fehler, kombinierten Name ergänzen
                            // Product / UserService
                            model.CategoryTypes.CategoryGroups = await _colibriDbContext.CategoryGroups.Where(m => m.Id == model.CategoryTypes.CategoryGroupId).FirstOrDefaultAsync();

                            if (model.CategoryTypes.CategoryGroups.TypeOfCategoryGroup.Equals("Product"))
                            {
                                model.CategoryTypes.NameCombined = "Product - " + model.CategoryTypes.CategoryGroups.Name + " - " + model.CategoryTypes.Name;
                            }
                            else
                            {
                                model.CategoryTypes.NameCombined = "Service - " + model.CategoryTypes.CategoryGroups.Name + " - " + model.CategoryTypes.Name;
                            }

                            // Eintrag in DB schreiben
                            _colibriDbContext.Add(model.CategoryTypes);
                            await _colibriDbContext.SaveChangesAsync();


                            // Publish the Created Category Type
                            using (var bus = RabbitHutch.CreateBus("host=localhost"))
                            {
                                //bus.Publish(categoryTypes, "create_category_types");
                                await bus.SendAsync("create_category_types", model.CategoryTypes);
                            }

                            return(RedirectToAction(nameof(Index)));
                        }
                    }
                }
            }

            // If ModelState is not valid
            CategoryTypesAndCategoryGroupsViewModel modelVM = new CategoryTypesAndCategoryGroupsViewModel()
            {
                CategoryGroupsList = _colibriDbContext.CategoryGroups.ToList(),
                CategoryTypes      = model.CategoryTypes,
                CategoryTypesList  = _colibriDbContext.CategoryTypes.OrderBy(p => p.Name).Select(p => p.Name).ToList(),
                StatusMessage      = StatusMessage
            };

            return(View(modelVM));
        }