public async Task <int> AddNew(AddNewViewModel input, IFormFile NewImage)
        {
            if (NewImage.Length > 0)
            {
                using (var stream = new MemoryStream())
                {
                    await NewImage.CopyToAsync(stream);

                    input.NewImage = stream.ToArray();
                }
            }

            int byteCount = input.NewImage.Length;

            if (byteCount > 265000)
            {
                return(0);
            }

            var currentNew = new New
            {
                Id = input.Id,
                PhotographyAddictedUserId = input.PhotographyAddictedUserId,
                NewImage     = input.NewImage,
                Title        = input.Title,
                TextContent  = input.TextContent,
                CreationDate = DateTime.UtcNow,
            };

            await newDbSet.AddAsync(currentNew);

            await newDbSet.SaveChangesAsync();

            return(currentNew.Id);
        }
示例#2
0
        // GET:
        public ActionResult Add()
        {
            var         viewModel   = new AddNewViewModel();
            LayoutModel layoutModel = new LayoutModel <AddNewViewModel>(pageModel: viewModel, title: "Test", toDoId: 1);

            return(View(layoutModel));
        }
        public IActionResult AddNew(AddNewViewModel vm)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var category = new AwardCategory()
                {
                    Category    = vm.Category,
                    Description = vm.Description
                };

                var result = this.Services.SaveCategory(category);
                if (result != null)
                {
                    return(RedirectToAction("Index"));
                }

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }
        }
示例#4
0
 public AddNewPage()
 {
     InitializeComponent();
     CarouselItems.IsVisible = false;
     isFirstPost             = true;
     addNewViewModel         = new AddNewViewModel();
     InicijalnizirajDataStorage();
 }
示例#5
0
        public IActionResult AddCustomer(CustomerDTO customer)
        {
            string username = this.HttpContext.Session.GetString(SessionConstant.UserNameSession);

            if (string.IsNullOrEmpty(username))
            {
                return(RedirectToAction("Login", "Account"));
            }

            var addNewVM    = new AddNewViewModel();
            var customers   = this._customerRepository.GetCustomers().ToList();
            var customersVM = this._mapper.Map <IEnumerable <Customer>, IEnumerable <CustomerDTO> >(customers);

            addNewVM.ExistingCustomers = customersVM;

            if (!ModelState.IsValid)
            {
                addNewVM.Customer = customer;
                return(View("AddNew", addNewVM));
            }

            bool isExisting = this._customerRepository.IsExistingByFirstLastName(
                customer.FirstName,
                customer.LastName,
                customer.Id
                );

            if (isExisting)
            {
                ModelState.AddModelError("", "Có khách hàng đã tồn tại với họ tên này. Xin chọn một tên khác.");
                addNewVM.Customer = customer;
                return(View("AddNew", addNewVM));
            }

            var customerDb = this._mapper.Map <Customer>(customer);

            customerDb.Picture     = "default.gif";
            customerDb.Balance     = 0;
            customerDb.CreatedDate = DateTime.Now;
            customerDb.CreatedBy   = "admin";
            customerDb.UpdatedDate = DateTime.Now;
            customerDb.UpdatedBy   = "admin";
            bool success = this._customerRepository.AddCustomer(customerDb);

            if (success)
            {
                TempData["Success"] = "Cập nhật dữ liệu thành công !";
                return(RedirectToAction("Index", "SalesTransaction", new { customerId = customerDb.Id }));
            }
            else
            {
                ModelState.AddModelError("", "Cập nhật dữ liệu thất bại !");
                addNewVM.Customer = customer;
                return(View("AddNew", addNewVM));
            }
        }
示例#6
0
        public IActionResult AddNew()
        {
            string username = this.HttpContext.Session.GetString(SessionConstant.UserNameSession);

            if (string.IsNullOrEmpty(username))
            {
                return(RedirectToAction("Login", "Account"));
            }

            var addNewVM    = new AddNewViewModel();
            var customers   = this._customerRepository.GetCustomers().ToList();
            var customersVM = this._mapper.Map <IEnumerable <Customer>, IEnumerable <CustomerDTO> >(customers);

            addNewVM.ExistingCustomers = customersVM;
            return(View(addNewVM));
        }
示例#7
0
        public async Task <IActionResult> AddNew(AddNewViewModel input, IFormFile NewImage)
        {
            if (ModelState.IsValid)
            {
                input.PhotographyAddictedUserId = this.User.FindFirstValue(ClaimTypes.NameIdentifier);

                var newId = await newService.AddNew(input, NewImage);

                if (newId == 0)
                {
                    ModelState.AddModelError(string.Empty, "Picture is bigger than 256kb");
                    return(this.View(input));
                }

                return(this.RedirectToAction("PreviewNews", "News"));
            }
            else
            {
                return(this.View(input));
            }
        }
示例#8
0
        public IActionResult AddNew(AddNewViewModel AddUser)
        {
            if (ModelState.IsValid)
            {
                var newUser = new UserDto()
                {
                    FirstName = AddUser.FirstName,
                    Surname   = AddUser.Surname,
                    Age       = AddUser.Age,
                    BirthDate = AddUser.BirthDate.Date,
                    Salary    = AddUser.Salary
                };

                _Context.Users.Add(newUser);
                _Context.SaveChanges();


                return(RedirectToAction("Index", "Home"));
            }
            return(View(AddUser));
        }
示例#9
0
        public AddNewPage(Advertisement advertisement)
        {
            using (MaterialDialog.Instance.LoadingDialogAsync(message: "Pričekajte..").Result)
            {
                addNewViewModel = new AddNewViewModel {
                    Advertisement = advertisement
                };
                isFirstPost = false;
                //data storage initialize
                InicijalnizirajDataStorage();
                foreach (var imageUrl in addNewViewModel.Advertisement.PicturesURL)
                {
                    addNewViewModel.ImageSourcesUri.Add(ImageSource.FromUri(new Uri(imageUrl)));
                }

                BindingContext = addNewViewModel;
                InitializeComponent();
                CarouselItems.IsVisible = true;
                SetUpEditView();
            }
        }
示例#10
0
        public IActionResult ExistingCustomer(AddNewViewModel model)
        {
            string username = this.HttpContext.Session.GetString(SessionConstant.UserNameSession);

            if (string.IsNullOrEmpty(username))
            {
                return(RedirectToAction("Login", "Account"));
            }

            var salesTransactionViewModel = new SalesTransactionVievModel();
            var customer = this._customerRepository.GetCustomerById(model.ExistingCustomerId);

            if (customer == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                return(RedirectToAction("Index", "SalesTransaction",
                                        new { customerId = model.ExistingCustomerId }));
            }
        }
示例#11
0
 public SearchPage()
 {
     InitializeComponent();
     BindingContext  = viewModel = new AdvertismentsViewModel();
     addNewViewModel = new AddNewViewModel();
 }