public async Task <IActionResult> AddPatent(string title, IFormFile imagePath, string Description, string Contact, string Application, IFormFile FileDocument, Guid ClaimId, int CityId, int IpFilterId, Guid UserId) { try { UsersIpModel model = new UsersIpModel() { Title = title, ImagePath = imagePath, Description = Description, Contact = Contact, ClaimId = ClaimId, Application = Application, CityId = CityId, FileDocument = FileDocument, UserId = UserId, IpFilterId = IpFilterId, IpType = Core.IpType.Patent }; var data = await userIpService.AddPatent(model); return(StatusCode(StatusCodes.Status200OK, data)); } catch (Exception ex) { // Log exception code goes here return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } }
public async Task <UsersIp> AddPatent(UsersIpModel patentModel) { if (patentModel.Title == null || patentModel.Title == "") { throw new Exception($"Title is required. Please write a Title."); } if (await IsTitleDuplicate(patentModel.Title)) { throw new Exception($"'{patentModel.Title}' already exists. Please choose a different title."); } var image = await UploadedImage(patentModel.IpType, patentModel.ImagePath); if (image == null) { throw new Exception($"Image is required."); } var document = await UploadFile(patentModel.IpType, patentModel.FileDocument); if (document == null) { throw new Exception($"File is required."); } UsersIp patent = new UsersIp { Title = patentModel.Title, Description = patentModel.Description, IpType = IpType.Patent, Contact = patentModel.Contact, Application = patentModel.Application, Status = IpStatus.Registered, ClaimId = patentModel.ClaimId, CityId = patentModel.CityId, UserId = patentModel.UserId, IpFilterId = patentModel.IpFilterId, ImagePath = image.ImagePath, FileDocument = document.FileDocument, DocumentPath = document.DocumentPath }; await _dbContext.UsersIps.AddAsync(patent); await _dbContext.SaveChangesAsync(); return(patent); }