public DegreeDTO Save(DegreeForm form)
        {
            var          transaction = _humanManagerContext.Database.BeginTransaction();
            DegreeEntity entity      = null;

            try
            {
                string folderName            = SystemContant.Degrees_Uploading_Path;
                string uploadPath            = _hostingEnvironment.ContentRootPath;
                string newPath               = Path.Combine(uploadPath, folderName);
                UploadUtil.Uploader uploader = _uploadUtil.DoFileUploading(newPath, form.UploadedFile);

                DegreeEntity newEntity = _mapper.Map <DegreeEntity>(form);
                newEntity.ImageName = uploader.fileName;
                entity = _humanManagerContext.Degrees.Add(newEntity).Entity;
                _humanManagerContext.SaveChanges();
                transaction.Commit();

                DegreeDTO dto = _mapper.Map <DegreeDTO>(entity);
                return(dto);
            }
            catch
            {
                transaction.Rollback();
                return(null);
            }
        }
Example #2
0
        public ActionResult <Api <DegreeDTO> > New([FromForm] DegreeForm degForm)
        {
            DegreeDTO       dto    = _degreeService.Save(degForm);
            Api <DegreeDTO> result = new Api <DegreeDTO>(200, dto, "Add Success");

            return(Ok(result));
        }
        public DegreeDTO Save(DegreeEntity newEntity)
        {
            var          transaction = _humanManagerContext.Database.BeginTransaction();
            DegreeEntity entity      = null;

            try
            {
                entity = _humanManagerContext.Degrees.Add(newEntity).Entity;
                _humanManagerContext.SaveChanges();

                transaction.Commit();

                DegreeDTO dto = _mapper.Map <DegreeDTO>(entity);

                return(dto);
            }
            catch
            {
                transaction.Rollback();
                return(null);
            }
        }