public async Task <Tuple <bool, string> > AddNewStickerType(AddChatStickerTypeInputModel model) { if (this.db.StickerTypes.Any(x => x.Name.ToUpper() == model.Name.ToUpper())) { return(Tuple.Create( false, string.Format(ErrorMessages.StickerTypeAlreadyExist, model.Name.ToUpper()))); } var stickerType = new StickerType { Name = model.Name, Position = await this.db.StickerTypes .Select(x => x.Position) .OrderByDescending(x => x) .FirstOrDefaultAsync() + 1, }; var imageUrl = await ApplicationCloudinary.UploadImage( this.cloudinary, model.Image, string.Format(GlobalConstants.StickerTypeName, stickerType.Id), GlobalConstants.StickerTypeFolder); stickerType.Url = imageUrl; this.db.StickerTypes.Add(stickerType); await this.db.SaveChangesAsync(); return(Tuple.Create( true, string.Format(SuccessMessages.SuccessfullyAddedStickerType, stickerType.Name.ToUpper()))); }
public async Task <IActionResult> AddNewStickerType(AddChatStickerTypeInputModel model) { if (this.ModelState.IsValid) { Tuple <bool, string> result = await this.addChatStickerTypeService.AddNewStickerType(model); if (!result.Item1) { this.TempData["Error"] = result.Item2; return(this.RedirectToAction("Index", "AddChatStickerType", model)); } this.TempData["Success"] = result.Item2; return(this.RedirectToAction("Index", "AddChatStickerType")); } this.TempData["Error"] = ErrorMessages.InvalidInputModel; return(this.RedirectToAction("Index", "AddChatStickerType", model)); }