public ActionResult AddImage(Image image)
 {
     if (Request.Files.Count > 0)
     {
         string fileName  = Path.GetFileName(Request.Files[0].FileName);
         string expansion = Path.GetExtension(Request.Files[0].FileName);
         string path      = "/AdminLTE-3.0.4/images/" + fileName + expansion;
         Request.Files[0].SaveAs(Server.MapPath(path));
         image.ImagePath = "/AdminLTE-3.0.4/images/" + fileName + expansion;
         im.Add(image);
         return(RedirectToAction("Index"));
     }
     return(View());
 }
Esempio n. 2
0
        public IActionResult AddImage(string title, IFormFile file)
        {
            ImageManager mgr   = new ImageManager(_connectionString);
            Image        image = new Image();

            image.Title = title;
            string fileName = $"{Guid.NewGuid()}{Path.GetExtension(file.FileName)}";
            string fullPath = Path.Combine(_environment.WebRootPath, "uploadedfiles", fileName);

            using (FileStream stream = new FileStream(fullPath, FileMode.CreateNew))
            {
                file.CopyTo(stream);
            }
            image.FileName = fileName;
            image.Like     = 0;
            mgr.Add(image);
            return(Redirect("/"));
        }
Esempio n. 3
0
        private void UpDate(string path, int ServiceId)
        {
            var image = new ImageManager();
            var model = new ImageInfoDbModel();

            model.CreateDate    = DateTime.Now;
            model.ImageName     = path;
            model.ImageServerId = ServiceId;
            image.Add(model);

            var ImageService = new ImageServiceManager();
            var dbmodel      = ImageService.Get(ServiceId);

            dbmodel.CurPicAmount++;
            if (dbmodel.CurPicAmount >= dbmodel.MaxPicAmount)
            {
                dbmodel.FlgUsable = false;
            }
            ImageService.Update(dbmodel);
        }
        public ActionResult CreateAndroid(EditAndroidViewModel model)
        {
            var jobList = new SelectList(_jobManager.GetList(), "Id", "Name", model.JobId);

            ViewBag.JobList = jobList;

            if (!ModelState.IsValid)
            {
                return(View("NewAndroid", model));
            }

            // Avatar
            Image  image;
            Stream imageStream = new MemoryStream();

            Resources.DefaultImage.Save(imageStream, System.Drawing.Imaging.ImageFormat.Jpeg);
            if (model.Avatar != null)
            {
                image       = new Image();
                imageStream = model.Avatar.InputStream;

                using (Stream inputStream = imageStream)
                {
                    MemoryStream memoryStream = inputStream as MemoryStream;
                    if (memoryStream == null)
                    {
                        memoryStream = new MemoryStream();
                        inputStream.CopyTo(memoryStream);
                    }
                    image.ImageData = memoryStream.ToArray();
                }
                _imageManager.Add(image);
            }
            else
            {
                image = _imageManager.GetDefaultImage();
            }

            // Skills
            var skillNames = model.Skills.Split(',');
            var skillList  = skillNames.Select(s => _skillManager.GetOrCreateSkillByName(s)).ToList();

            var android = new Android()
            {
                Name        = model.Name,
                Avatar      = image,
                Skills      = skillList,
                Reliability = model.Reliability
            };

            _androidManager.Add(android);

            // Job
            if (model.JobId != null)
            {
                var job = _jobManager.GetById((int)model.JobId);
                _jobManager.AssignAndroidToJob(job, android);
            }

            return(RedirectToAction("AndroidList", "Android"));
        }