Exemple #1
0
        public async Task Create(Setting model, List <IFormFile> logo, List <IFormFile> favicon)
        {
            if (logo.Count == 0)
            {
                model.Logo = model.Logo;
            }
            else
            {
                var fileName = await _upload.UploadFile(logo, _env);

                model.Logo = "/Uploads/" + fileName;
            }

            if (favicon.Count == 0)
            {
                model.Favicon = model.Favicon;
            }
            else
            {
                var fileName = await _upload.UploadFile(favicon, _env);

                model.Favicon = "/Uploads/" + fileName;
            }
            _context.Add(model);
            await _context.SaveChangesAsync();
        }
        public async Task <IActionResult> NewDoctor(DoctorDto model, List <IFormFile> files)
        {
            var ee = "";

            if (ModelState.IsValid)
            {
                try
                {
                    string succed;

                    succed = await _doctor.Create(model);

                    if (succed == "true")
                    {
                        var user = await userManager.FindByNameAsync(model.EmailAddress);

                        var user1 = await _context.Doctor.FirstOrDefaultAsync(x => x.UserId == user.Id);

                        //try to update the Doctor Reg
                        //Doctor Reg
                        string numberid = user1.Id.ToString("D3");
                        user1.DoctorReg = "DOC/" + numberid;

                        //try to update the user profile pict
                        //profile pic upload
                        var fileName = await _upload.UploadFile(files, _env);

                        user1.ProfilePicture        = "/Uploads/" + fileName;
                        _context.Entry(user1).State = EntityState.Modified;
                        await _context.SaveChangesAsync();



                        TempData["success"] = "Doctor with Username " + model.Fullname + "Added Successfully";
                        return(RedirectToAction("NewDoctor"));
                    }
                    else
                    {
                        TempData["error1"] = succed;
                    }
                }
                catch (Exception e)
                {
                    ee = e.ToString();
                }
            }
            var allErrors = ModelState.Values.SelectMany(v => v.Errors);

            TempData["error"]        = "Creation of new Doctor not successful" + ee;
            ViewData["DepartmentId"] = new SelectList(_context.Departments, "Id", "DeptName", model.DepartmentId);
            ViewData["BloodGroupId"] = new SelectList(_context.BloodGroup, "Id", "Name", model.BloodGroupId);
            return(View(model));
        }
        public async Task <IActionResult> NewAccountant(AccountantDto model, List <IFormFile> files)
        {
            var ee = "";

            if (ModelState.IsValid)
            {
                try
                {
                    string succed;

                    succed = await _accountant.Create(model);

                    if (succed == "true")
                    {
                        var user = await userManager.FindByNameAsync(model.Email);

                        var user1 = await _context.Accountants.FirstOrDefaultAsync(x => x.UserId == user.Id);

                        //try to update the Accountant Reg
                        //Accountant Reg
                        string numberid = user1.Id.ToString("D3");
                        user1.AccountantReg = "ACCT/" + numberid;

                        //try to update the user profile pict
                        //profile pic upload
                        var fileName = await _upload.UploadFile(files, _env);

                        user1.ProfilePicture        = "/Uploads/" + fileName;
                        _context.Entry(user1).State = EntityState.Modified;
                        await _context.SaveChangesAsync();



                        TempData["success"] = "Accountant with Username " + model.Fullname + "Added Successfully";
                        return(RedirectToAction("NewAccountant"));
                    }
                    else
                    {
                        TempData["error1"] = succed;
                    }
                }
                catch (Exception e)
                {
                    ee = e.ToString();
                }
            }
            var allErrors = ModelState.Values.SelectMany(v => v.Errors);

            TempData["error"] = "Creation of new Accountant not successful" + ee;
            return(View(model));
        }
        public async Task Edit(Doctor model, List <IFormFile> files)
        {
            if (files.Count == 0)
            {
                model.ProfilePicture = model.ProfilePicture;
            }
            else
            {
                var fileName = await _upload.UploadFile(files, _env);

                model.ProfilePicture = "/Uploads/" + fileName;
            }
            _context.Entry(model).State = EntityState.Modified;
            await _context.SaveChangesAsync();
        }
Exemple #5
0
        public JsonResult UploadBanner(string id)
        {
            try
            {
                HttpPostedFileBase uploadImage = Request.Files[0];
                string             imgFileName = String.Empty; //返回的图片路径
                string             imgErr      = String.Empty; //返回的上传错误信息
                if (uploadImage != null && uploadImage.ContentLength > 0)
                {
                    IUpload      upload     = UploadProvider.GetInstance();
                    UpFileEntity fileEntity = new UpFileEntity()
                    {
                        Size = 4096, AllowType = ".jpg,.jpeg,.bmp,.gif,.png"
                    };
                    fileEntity.Dir       = "/Plugin/";
                    fileEntity.AllowType = ".jpg,.jpeg,.gif,.png,.bmp";

                    AttachmentInfo attch = upload.UploadFile(uploadImage, fileEntity);

                    if (attch != null && string.IsNullOrEmpty(attch.Error))
                    {
                        imgFileName = attch.FileName;
                    }
                    else
                    {
                        imgErr = attch.Error;
                    }
                }
                else
                {
                    imgErr = "请选择上传文件";
                }
                var res    = new JsonResult();
                var person = new { err = imgErr, msg = imgFileName };
                res.Data            = person;//返回单个对象
                res.ContentType     = "application/javascript";
                res.ContentEncoding = Encoding.UTF8;
                return(res);
            }
            catch (Exception ex)
            {
                throw new Exception("上传文件测试", ex);
            }
        }