public IActionResult Create([FromBody] ProductTypeDTO productTypeDTO) { ProductType productType = new ProductType(); productType.ProductTypeName = productTypeDTO.ProductTypeName; var productTypeEntity = _productTypesService.Create(productType); var productTypes = _mapper.Map <ProductTypeDTO>(productTypeEntity); return(Ok(productType)); }
public async Task <IActionResult> Create([FromBody] CreateProductType request) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var resultId = await _productTypeService.Create(request); if (!resultId.IsSuccessed) { return(BadRequest(resultId)); } var result = await _productTypeService.GetById(resultId.ResultObj); return(Ok(result)); }
public async Task <ActionResult <ProductTypeDetail_ProductTypeDTO> > Create([FromBody] ProductTypeDetail_ProductTypeDTO ProductTypeDetail_ProductTypeDTO) { if (!ModelState.IsValid) { throw new MessageException(ModelState); } ProductType ProductType = ConvertDTOToEntity(ProductTypeDetail_ProductTypeDTO); ProductType = await ProductTypeService.Create(ProductType); ProductTypeDetail_ProductTypeDTO = new ProductTypeDetail_ProductTypeDTO(ProductType); if (ProductType.IsValidated) { return(ProductTypeDetail_ProductTypeDTO); } else { return(BadRequest(ProductTypeDetail_ProductTypeDTO)); } }
public ActionResult Post(ProductType ptt) { if (ModelState.IsValid) { if (ptt.ProductTypeId <= 0) { ProductType pt1 = new ProductType(); pt1.ProductNatureId = ptt.ProductNatureId; pt1.ProductTypeName = ptt.ProductTypeName; pt1.IsPostedInStock = ptt.IsPostedInStock; pt1.CreatedDate = DateTime.Now; pt1.ModifiedDate = DateTime.Now; pt1.IsActive = ptt.IsActive; pt1.CreatedBy = User.Identity.Name; pt1.ModifiedBy = User.Identity.Name; pt1.ObjectState = Model.ObjectState.Added; var createdProductType = _ProductTypeService.Create(pt1); try { _unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); ModelState.AddModelError("", message); return(View("Create", ptt)); } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.ProductType).DocumentTypeId, DocId = pt1.ProductTypeId, ActivityType = (int)ActivityTypeContants.Added, })); #region //Saving Images if any uploaded after UnitOfWorkSave if (Request.Files[0] != null && Request.Files[0].ContentLength > 0) { //For checking the first time if the folder exists or not----------------------------- string uploadfolder; int MaxLimit; int.TryParse(ConfigurationManager.AppSettings["MaxFileUploadLimit"], out MaxLimit); var x = (from iid in db.Counter select iid).FirstOrDefault(); if (x == null) { uploadfolder = System.Guid.NewGuid().ToString(); Counter img = new Counter(); img.ImageFolderName = uploadfolder; img.ModifiedBy = User.Identity.Name; img.CreatedBy = User.Identity.Name; img.ModifiedDate = DateTime.Now; img.CreatedDate = DateTime.Now; new CounterService(_unitOfWork).Create(img); _unitOfWork.Save(); } else { uploadfolder = x.ImageFolderName; } //For checking if the image contents length is greater than 100 then create a new folder------------------------------------ if (!Directory.Exists(System.Web.HttpContext.Current.Request.MapPath("~/Uploads/" + uploadfolder))) { Directory.CreateDirectory(System.Web.HttpContext.Current.Request.MapPath("~/Uploads/" + uploadfolder)); } int count = Directory.GetFiles(System.Web.HttpContext.Current.Request.MapPath("~/Uploads/" + uploadfolder)).Length; if (count >= MaxLimit) { uploadfolder = System.Guid.NewGuid().ToString(); var u = new CounterService(_unitOfWork).Find(x.CounterId); u.ImageFolderName = uploadfolder; new CounterService(_unitOfWork).Update(u); _unitOfWork.Save(); } //Saving Thumbnails images: Dictionary <string, string> versions = new Dictionary <string, string>(); //Define the versions to generate versions.Add("_thumb", "maxwidth=100&maxheight=100"); //Crop to square thumbnail versions.Add("_medium", "maxwidth=200&maxheight=200"); //Fit inside 400x400 area, jpeg string temp2 = ""; string filename = System.Guid.NewGuid().ToString(); foreach (string filekey in System.Web.HttpContext.Current.Request.Files.Keys) { HttpPostedFile pfile = System.Web.HttpContext.Current.Request.Files[filekey]; if (pfile.ContentLength <= 0) { continue; //Skip unused file controls. } temp2 = Path.GetExtension(pfile.FileName); string uploadFolder = System.Web.HttpContext.Current.Request.MapPath("~/Uploads/" + uploadfolder); if (!Directory.Exists(uploadFolder)) { Directory.CreateDirectory(uploadFolder); } string filecontent = Path.Combine(uploadFolder, pt1.ProductTypeName + "_" + filename); //pfile.SaveAs(filecontent); ImageBuilder.Current.Build(new ImageJob(pfile, filecontent, new Instructions(), false, true)); //Generate each version foreach (string suffix in versions.Keys) { if (suffix == "_thumb") { string tuploadFolder = System.Web.HttpContext.Current.Request.MapPath("~/Uploads/" + uploadfolder + "/Thumbs"); if (!Directory.Exists(tuploadFolder)) { Directory.CreateDirectory(tuploadFolder); } //Generate a filename (GUIDs are best). string tfileName = Path.Combine(tuploadFolder, pt1.ProductTypeName + "_" + filename); //Let the image builder add the correct extension based on the output file type //fileName = ImageBuilder.Current.Build(file, fileName, new ResizeSettings(versions[suffix]), false, true); ImageBuilder.Current.Build(new ImageJob(pfile, tfileName, new Instructions(versions[suffix]), false, true)); } else if (suffix == "_medium") { string tuploadFolder = System.Web.HttpContext.Current.Request.MapPath("~/Uploads/" + uploadfolder + "/Medium"); if (!Directory.Exists(tuploadFolder)) { Directory.CreateDirectory(tuploadFolder); } //Generate a filename (GUIDs are best). string tfileName = Path.Combine(tuploadFolder, pt1.ProductTypeName + "_" + filename); //Let the image builder add the correct extension based on the output file type //fileName = ImageBuilder.Current.Build(file, fileName, new ResizeSettings(versions[suffix]), false, true); ImageBuilder.Current.Build(new ImageJob(pfile, tfileName, new Instructions(versions[suffix]), false, true)); } } //var tempsave = _FinishedProductService.Find(pt.ProductId); pt1.ImageFileName = ptt.ProductTypeName + "_" + filename + temp2; pt1.ImageFolderName = uploadfolder; pt1.ObjectState = Model.ObjectState.Modified; _ProductTypeService.Update(pt1); _unitOfWork.Save(); } } #endregion return(RedirectToAction("Create").Success("Data saved successfully")); } else { List <LogTypeViewModel> LogList = new List <LogTypeViewModel>(); ProductType temp = _ProductTypeService.Find(ptt.ProductTypeId); ProductType ExRec = Mapper.Map <ProductType>(temp); temp.ProductNatureId = ptt.ProductNatureId; temp.ProductTypeName = ptt.ProductTypeName; temp.IsPostedInStock = ptt.IsPostedInStock; temp.IsActive = ptt.IsActive; temp.ModifiedDate = DateTime.Now; temp.ModifiedBy = User.Identity.Name; temp.ObjectState = Model.ObjectState.Modified; _ProductTypeService.Update(temp); LogList.Add(new LogTypeViewModel { ExObj = ExRec, Obj = temp, }); XElement Modifications = new ModificationsCheckService().CheckChanges(LogList); try { _unitOfWork.Save(); } catch (Exception ex) { string message = _exception.HandleException(ex); ModelState.AddModelError("", message); return(View("Create", ptt)); } LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel { DocTypeId = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.ProductType).DocumentTypeId, DocId = temp.ProductTypeId, ActivityType = (int)ActivityTypeContants.Modified, xEModifications = Modifications, })); #region //Saving Image if file is uploaded if (Request.Files[0] != null && Request.Files[0].ContentLength > 0) { string uploadfolder = temp.ImageFolderName; string tempfilename = temp.ImageFileName; if (uploadfolder == null) { var x = (from iid in db.Counter select iid).FirstOrDefault(); if (x == null) { uploadfolder = System.Guid.NewGuid().ToString(); Counter img = new Counter(); img.ImageFolderName = uploadfolder; img.ModifiedBy = User.Identity.Name; img.CreatedBy = User.Identity.Name; img.ModifiedDate = DateTime.Now; img.CreatedDate = DateTime.Now; new CounterService(_unitOfWork).Create(img); _unitOfWork.Save(); } else { uploadfolder = x.ImageFolderName; } } //Deleting Existing Images var xtemp = System.Web.HttpContext.Current.Server.MapPath("~/Uploads/" + uploadfolder + "/" + tempfilename); if (System.IO.File.Exists(System.Web.HttpContext.Current.Server.MapPath("~/Uploads/" + uploadfolder + "/" + tempfilename))) { System.IO.File.Delete(System.Web.HttpContext.Current.Server.MapPath("~/Uploads/" + uploadfolder + "/" + tempfilename)); } //Deleting Thumbnail Image: if (System.IO.File.Exists(System.Web.HttpContext.Current.Server.MapPath("~/Uploads/" + uploadfolder + "/Thumbs/" + tempfilename))) { System.IO.File.Delete(System.Web.HttpContext.Current.Server.MapPath("~/Uploads/" + uploadfolder + "/Thumbs/" + tempfilename)); } //Deleting Medium Image: if (System.IO.File.Exists(System.Web.HttpContext.Current.Server.MapPath("~/Uploads/" + uploadfolder + "/Medium/" + tempfilename))) { System.IO.File.Delete(System.Web.HttpContext.Current.Server.MapPath("~/Uploads/" + uploadfolder + "/Medium/" + tempfilename)); } //Saving Thumbnails images: Dictionary <string, string> versions = new Dictionary <string, string>(); //Define the versions to generate versions.Add("_thumb", "maxwidth=100&maxheight=100"); //Crop to square thumbnail versions.Add("_medium", "maxwidth=200&maxheight=200"); //Fit inside 400x400 area, jpeg string temp2 = ""; string filename = System.Guid.NewGuid().ToString(); foreach (string filekey in System.Web.HttpContext.Current.Request.Files.Keys) { HttpPostedFile pfile = System.Web.HttpContext.Current.Request.Files[filekey]; if (pfile.ContentLength <= 0) { continue; //Skip unused file controls. } temp2 = Path.GetExtension(pfile.FileName); string uploadFolder = System.Web.HttpContext.Current.Request.MapPath("~/Uploads/" + uploadfolder); if (!Directory.Exists(uploadFolder)) { Directory.CreateDirectory(uploadFolder); } string filecontent = Path.Combine(uploadFolder, temp.ProductTypeName + "_" + filename); //pfile.SaveAs(filecontent); ImageBuilder.Current.Build(new ImageJob(pfile, filecontent, new Instructions(), false, true)); //Generate each version foreach (string suffix in versions.Keys) { if (suffix == "_thumb") { string tuploadFolder = System.Web.HttpContext.Current.Request.MapPath("~/Uploads/" + uploadfolder + "/Thumbs"); if (!Directory.Exists(tuploadFolder)) { Directory.CreateDirectory(tuploadFolder); } //Generate a filename (GUIDs are best). string tfileName = Path.Combine(tuploadFolder, temp.ProductTypeName + "_" + filename); //Let the image builder add the correct extension based on the output file type //fileName = ImageBuilder.Current.Build(file, fileName, new ResizeSettings(versions[suffix]), false, true); ImageBuilder.Current.Build(new ImageJob(pfile, tfileName, new Instructions(versions[suffix]), false, true)); } else if (suffix == "_medium") { string tuploadFolder = System.Web.HttpContext.Current.Request.MapPath("~/Uploads/" + uploadfolder + "/Medium"); if (!Directory.Exists(tuploadFolder)) { Directory.CreateDirectory(tuploadFolder); } //Generate a filename (GUIDs are best). string tfileName = Path.Combine(tuploadFolder, temp.ProductTypeName + "_" + filename); //Let the image builder add the correct extension based on the output file type //fileName = ImageBuilder.Current.Build(file, fileName, new ResizeSettings(versions[suffix]), false, true); ImageBuilder.Current.Build(new ImageJob(pfile, tfileName, new Instructions(versions[suffix]), false, true)); } } } var temsave = _ProductTypeService.Find(temp.ProductTypeId); temsave.ImageFileName = temsave.ProductTypeName + "_" + filename + temp2; temsave.ImageFolderName = uploadfolder; _ProductTypeService.Update(temsave); _unitOfWork.Save(); } #endregion return(RedirectToAction("Index").Success("Data saved successfully")); } } PrepareViewBag(); return(View("Create", ptt)); }
public IHttpActionResult Create(ProductType request) { _productFamilyService.Create(request); return(Ok()); }
public async Task <IActionResult> CreateProductType(ProductTypeCreateRequest request) { var tempId = await _productTypeService.Create(request); return(Ok(tempId)); }