public GenericResults <InsertBookModel> SaveModel(InsertBookModel model, List <string> imageUrls) { var db_book = _bookRepository.GetByISBN13(model.ISBN13); GenericResults <InsertBookModel> genericModel = new GenericResults <InsertBookModel>(); if (db_book != null) { genericModel.AddError(ErrorMessageCode.BookAlreadyExists, "ISBN13 Numarası zaten daha önce kayıt edilmiş!"); return(genericModel); } var IsbnCheck = IsDigitsOnly(model.ISBN13); if ((!IsbnCheck) || model.ISBN13.Length != 13) { genericModel.AddError(ErrorMessageCode.WrongFormat, "ISBN13 Barkod numarası sadece rakam içermesi gerekir ve 13 rakamdan oluşmalıdır"); return(genericModel); } Book entity = new Book { Title = model.Title, Description = model.Description, PublicationDate = model.PublicationDate, Price = model.Price, ISBN13 = model.ISBN13, Page = model.Page, PublisherId = model.PublisherId, AuthorId = model.AuthorId, Stock = model.Stock }; var generatedBookId = _bookRepository.Save(entity); if (generatedBookId == 0) { genericModel.AddError(ErrorMessageCode.SomethingWentWrong, "Bir Hata oluştu. Lütfen tekrar deneyiniz!"); return(genericModel); } int imageResult = this.InsertBookImages(imageUrls, generatedBookId); var bookCategories = string.Join(",", model.CategoryIds); int categoryResult = _bookRepository.SaveBookCategories(bookCategories, generatedBookId); if (imageResult == 0 || categoryResult == 0) { genericModel.AddError(ErrorMessageCode.SomethingWentWrong, "Bir Hata oluştu. Lütfen tekrar deneyiniz!"); return(genericModel); } return(genericModel); }
public GenericResults <Publisher> SaveModel(Publisher model) { var db_publisher = _publisherRepository.CheckByName(model.Name); GenericResults <Publisher> genericModel = new GenericResults <Publisher>(); if (db_publisher != null) { genericModel.AddError(ErrorMessageCode.PublisherAlreadyExists, "Bu Yayınevi zaten sistemde Kayıtlı!"); return(genericModel); } genericModel.Model = this.PrepareEntity(model); int result = _publisherRepository.Save(genericModel.Model); if (result == 0) { genericModel.AddError(ErrorMessageCode.SomethingWentWrong, "Bir hata oluştu. Lütfen Tekrar Deneyiniz!"); } return(genericModel); }
public GenericResults <Author> SaveModel(Author model) { var db_author = _authorRepository.CheckByName(model.Name); GenericResults <Author> updateModel = new GenericResults <Author>(); if (db_author != null) { updateModel.AddError(ErrorMessageCode.AuthorAlreadyExists, "Bu yazar zaten sistemde Kayıtlı!"); return(updateModel); } updateModel.Model = this.PrepareEntity(model); int result = _authorRepository.Save(updateModel.Model); if (result == 0) { updateModel.AddError(ErrorMessageCode.SomethingWentWrong, "Bir hata oluştu. Lütfen Tekrar Deneyiniz!"); } return(updateModel); }
public GenericResults <Category> SaveModel(Category model) { var db_category = _categoryRepository.CheckByName(model.Title); GenericResults <Category> updateModel = new GenericResults <Category>(); if (db_category != null) { updateModel.AddError(ErrorMessageCode.CategoryALreadyExists, "Bu kategori daha önce kayıt edilmiş!"); return(updateModel); } updateModel.Model = this.PrepareEntity(model); int result = _categoryRepository.Save(updateModel.Model); if (result == 0) { updateModel.AddError(ErrorMessageCode.SomethingWentWrong, "Bir şeyler yanlış gitti. Tekrar deneyiniz!"); } return(updateModel); }