public ActionResult Create(int ServiceId, HttpPostedFileBase Photo)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            var service = _context.Services.Find(ServiceId);

            if (service == null)
            {
                return(HttpNotFound("Service Item yok la"));
            }
            ServicePortfolio servicePortfolio = new ServicePortfolio
            {
                ServiceId = ServiceId
            };


            if (Photo != null)
            {
                if (!Photo.IsImage())
                {
                    ModelState.AddModelError("Photo", "Photo type is not valid");

                    return(View());
                }

                servicePortfolio.Image = Photo.SavePhoto("Assets/img", "servicePortfolios");
            }

            _context.ServicePortfolios.Add(servicePortfolio);
            _context.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public ActionResult Create(int ServiceId, int BarberId)
        {
            //var ServiceI = _context.Services.Find(ServiceId);
            //var BarberI = _context.Services.Find(BarberId);
            ServicetoBarber servicetoBarber = new ServicetoBarber
            {
                ServiceId = ServiceId,
                BarberId  = BarberId
            };

            _context.ServicetoBarbers.Add(servicetoBarber);
            _context.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public ActionResult Create(int BarberId, HttpPostedFileBase Photo)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            var barber = _context.Barbers.Find(BarberId);

            if (barber == null)
            {
                return(HttpNotFound("Service Item yok la"));
            }
            BarberImage barberImage = new BarberImage
            {
                BarberId = BarberId
            };


            if (Photo != null)
            {
                if (!Photo.IsImage())
                {
                    ModelState.AddModelError("Photo", "Photo type is not valid");

                    return(View());
                }

                barberImage.Image = Photo.SavePhoto("Assets/img", "barberImages");
            }

            _context.BarberImages.Add(barberImage);
            _context.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public ActionResult Create([Bind(Include = "Name,Description,Price,DataFilter,Photo")] Service service)
        {
            if (!ModelState.IsValid)
            {
                return(View(service));
            }
            // ilk once bu servicin movcud olub olmadigini yoxla
            if (_context.Services.Any(s => s.Name == service.Name || s.DataFilter == service.DataFilter))
            {
                ModelState.AddModelError("Name", "Bu servis artiq movcuddur");
                ModelState.AddModelError("DataFilter", "Bu DataFilter artiq movcuddur");

                return(View(service));
            }

            ////
            if (service.Photo == null)
            {
                ModelState.AddModelError("Photo", "Photo should be selected");

                return(View(service));
            }
            /////
            if (!service.Photo.IsImage())
            {
                ModelState.AddModelError("Photo", "Photo type is not valid");

                return(View(service));
            }

            service.Image = service.Photo.SavePhoto("Assets/img", "services");
            //if (service.Photo != null)
            //{
            //    if (!service.Photo.IsImage())
            //    {
            //        ModelState.AddModelError("Photo", "Photo type is not valid");

            //        return View(service);
            //    }

            //    service.Image = service.Photo.SavePhoto("Assets/img", "services");
            //}
            _context.Services.Add(service);
            _context.SaveChanges();
            return(RedirectToAction("Index"));
        }
示例#5
0
        public ActionResult Create([Bind(Include = "TitleOne,TitleTwo,Photo")] Slider sliderI)
        {
            if (!ModelState.IsValid)
            {
                return(View(sliderI));
            }
            if (sliderI.Photo != null)
            {
                if (!sliderI.Photo.IsImage())
                {
                    ModelState.AddModelError("Photo", "Photo type is not valid");

                    return(View(sliderI));
                }

                sliderI.Image = sliderI.Photo.SavePhoto("Assets/img", "slider");
            }

            _context.Sliders.Add(sliderI);
            _context.SaveChanges();

            return(RedirectToAction("Index"));
        }
        public ActionResult Create([Bind(Include = "Name,Surname,Description, Email, Tel,Photo")] Barber barber)
        {
            if (!ModelState.IsValid)
            {
                return(View(barber));
            }

            if (_context.Barbers.Any(b => b.Name == barber.Name && b.Surname == barber.Surname))
            {
                ModelState.AddModelError("Name", "Bu  berber movcuddur.");
                ModelState.AddModelError("Surname", "Bu  berber movcuddur.");

                return(View(barber));
            }

            if (barber.Photo == null)
            {
                ModelState.AddModelError("Photo", "Photo should be selected");

                return(View(barber));
            }

            if (!barber.Photo.IsImage())
            {
                ModelState.AddModelError("Photo", "Photo type is not valid");

                return(View(barber));
            }
            barber.Image = barber.Photo.SavePhoto("Assets/img", "barbers");
            //if(_context.Barbers.Any(b=>b.Name == barber.Name || b.Surname == barber.Surname))
            //{
            //    if (barber.Photo != null)
            //    {
            //        if (!barber.Photo.IsImage())
            //        {
            //            ModelState.AddModelError("Photo", "Photo type is not valid");

            //            return View(barber);
            //        }

            //        barber.Image = barber.Photo.SavePhoto("Assets/img", "barbers");
            //    }
            //    else
            //    {


            //        ModelState.AddModelError("Photo", "Photo should be selected");

            //        return View(barber);
            //    }

            //    ModelState.AddModelError("Name", "Bu  berber movcuddur.");
            //    ModelState.AddModelError("Surname", "Bu  berber movcuddur.");

            //    return View(barber);
            //}
            barber.BeganWork = DateTime.Now;
            _context.Barbers.Add(barber);
            _context.SaveChanges();
            return(RedirectToAction("Index"));
        }