public async Task <ActionResult> AddUpdateGame(DIBZ.Common.Model.GameCatalog request, HttpPostedFileBase file) { var gameCatalogLogic = LogicContext.Create <GameCatalogLogic>(); var serverPath = Server.MapPath("~/Uploads"); string fileName = string.Empty; if (file != null) { fileName = file.FileName; } var gameData = await gameCatalogLogic.AddUpdate(request, fileName); if (file != null) { var fileSizeInMB = file.ContentLength / 1024; var savePath = Path.Combine(serverPath, gameData.GameImage.Id.ToString()); if (fileSizeInMB >= 1024 * 1.65) { var originalFilePath = Path.Combine(serverPath, (gameData.GameImage.Id + 100).ToString()); file.SaveAs(originalFilePath); FileSaveHelper.ResizeTo(originalFilePath, 865, 500, savePath); System.IO.File.Delete(originalFilePath); } else { file.SaveAs(savePath); } } return(RedirectToAction("Index")); }
public async Task <bool> Delete(int id) { DIBZ.Common.Model.GameCatalog gameCatalog = null; if (id > 0) { gameCatalog = await GetGameCatalogById(id); } gameCatalog.IsDeleted = true; await Db.SaveAsync(); return(true); }
public async Task <ActionResult> AddUpdate(int?id) { var formatLogic = LogicContext.Create <FormatLogic>(); var categoryLogic = LogicContext.Create <CategoryLogic>(); var gameCatalogLogic = LogicContext.Create <GameCatalogLogic>(); DIBZ.Common.Model.GameCatalog gameCatalog = new DIBZ.Common.Model.GameCatalog(); if (id > 0) { gameCatalog = await gameCatalogLogic.GetGameCatalogById(Convert.ToInt32(id)); } ViewBag.Formats = await formatLogic.GetAllFormats(); ViewBag.Categories = await categoryLogic.GetAllCategories(); return(View(gameCatalog)); }
public async Task <DIBZ.Common.Model.GameCatalog> AddUpdateGameCatalog(GameCatalogModel request) { DIBZ.Common.Model.GameCatalog gameCatalog = null; if (request.Id > 0) { gameCatalog = await GetGameCatalogById(request.Id); } else { gameCatalog = new DIBZ.Common.Model.GameCatalog(); } gameCatalog.IsActive = true; gameCatalog.Description = request.Description; gameCatalog.FormatId = request.FormatId; await Db.SaveAsync(); return(gameCatalog); }
public async Task <DIBZ.Common.Model.GameCatalog> AddUpdate(DIBZ.Common.Model.GameCatalog request, string fileName) { DIBZ.Common.Model.GameCatalog gameCatalog = null; if (request.Id > 0) { gameCatalog = await GetGameCatalogById(request.Id); gameCatalog.Name = request.Name; gameCatalog.Description = request.Description; gameCatalog.FormatId = request.FormatId; gameCatalog.IsFeatured = request.IsFeatured; gameCatalog.CategoryId = request.CategoryId; if (!string.IsNullOrEmpty(fileName)) { gameCatalog.GameImage = new UploadedFile { Filename = fileName }; } else if (string.IsNullOrEmpty(fileName) && request.GameImageId > 0) { gameCatalog.GameImageId = request.GameImageId; } } else { if (string.IsNullOrEmpty(fileName) && request.GameImageId > 0) { gameCatalog = new DIBZ.Common.Model.GameCatalog { IsActive = true, Name = request.Name, Description = request.Description, FormatId = request.FormatId, CategoryId = request.CategoryId, IsFeatured = request.IsFeatured, GameImageId = request.GameImageId }; } else { var imgObj = new UploadedFile { Filename = fileName }; gameCatalog = new DIBZ.Common.Model.GameCatalog { IsActive = true, Name = request.Name, Description = request.Description, FormatId = request.FormatId, CategoryId = request.CategoryId, IsFeatured = request.IsFeatured, GameImage = imgObj }; } Db.Add(gameCatalog); } await Db.SaveAsync(); return(gameCatalog); }
public async Task <ActionResult> CreateOffer(int?id, int?offerId, int?gameId, int?returnGameId) { string view = ""; //Request.UrlReferrer;// == null ? null : Request.UrlReferrer.Segments[2]; //if (view == "MyOffers") if (!id.HasValue) { DIBZ.Common.Model.GameCatalog selectedGame = new DIBZ.Common.Model.GameCatalog(); var offerLogic = LogicContext.Create <OfferLogic>(); selectedGame = await offerLogic.GetSelectedGameById(gameId); ViewBag.SelectedGame = selectedGame; selectedGame = await offerLogic.GetSelectedGameById(returnGameId); ViewBag.DesiredGame = selectedGame; ViewBag.OfferId = offerId; ViewBag.View = "EditOffer"; } else { DIBZ.Common.Model.GameCatalog selectedGame = new DIBZ.Common.Model.GameCatalog(); var offerLogic = LogicContext.Create <OfferLogic>(); selectedGame = await offerLogic.GetSelectedGameById(id); ViewBag.SelectedGame = selectedGame; ViewBag.DesiredGame = selectedGame; } var offerlogic = LogicContext.Create <OfferLogic>(); var gameCatalogLogic = LogicContext.Create <GameCatalogLogic>(); var myGames = await gameCatalogLogic.GetAllGamesOfApplicationUser(CurrentLoginSession.ApplicationUserId.GetValueOrDefault()); var pageSize = Convert.ToInt16(PageSize.AllGames); if (TempData["searchGamesData"] != null) { var currentPage = Convert.ToInt16(TempData["currentPage"]); var searchCount = Convert.ToInt32(TempData["searchCount"]); var Pages = offerlogic.PagingLogic(currentPage - 1, pageSize, searchCount); ViewBag.Pages = Pages; ViewBag.FormatId = TempData["formatId"]; ViewBag.CategoryId = TempData["categoryId"]; ViewBag.GameName = TempData["gameName"]; ViewBag.GameCollection = TempData["searchGamesData"]; ViewBag.SelectedPage = currentPage; ViewBag.pageSize = pageSize; } else { SearchOffer Search = new SearchOffer(); Search.GameName = ""; Search.FormatId = 0; Search.CategoryId = 0; var currentPage = 1; var countAllGames = await gameCatalogLogic.SearchGameCatalog(CurrentLoginSession.ApplicationUserId.GetValueOrDefault(), Search, currentPage, true); var totalCount = Convert.ToInt32(countAllGames.Count); var Pages = offerlogic.PagingLogic(currentPage, pageSize, totalCount); ViewBag.Pages = Pages; ViewBag.FormatId = 0; ViewBag.CategoryId = 0; ViewBag.GameName = ""; ViewBag.GameCollection = await gameCatalogLogic.SearchGameCatalog(CurrentLoginSession.ApplicationUserId.GetValueOrDefault(), Search, currentPage, false); ViewBag.SelectedPage = 1; ViewBag.pageSize = pageSize; } var formatLogic = LogicContext.Create <FormatLogic>(); var formats = await formatLogic.GetAllFormats(); ViewBag.Formats = new SelectList(formats, "Id", "Name"); var categoryLogic = LogicContext.Create <CategoryLogic>(); var categories = await categoryLogic.GetAllCategories(); ViewBag.Categories = new SelectList(categories, "Id", "Name"); return(View(myGames)); }
public async Task <ActionResult> AddGameIntoCollection(string gameIds, int currentPage, string searchGame, int formatId, int categoryId) { DIBZDbContext context = new DIBZDbContext(); var authLogic = LogicContext.Create <AuthLogic>(); try { var notifierEmail = (from NotifierEmails in context.NotifierEmails orderby NotifierEmails.CreatedTime descending select new { EmailAddress = NotifierEmails.EmailAddress }).ToList(); var userId = CurrentLoginSession.ApplicationUserId.GetValueOrDefault(); var usersFirstGameData = (from ApplicationUser in context.ApplicationUsers where ApplicationUser.Id == userId select new GameData { GameName = ApplicationUser.GameCatalogs.FirstOrDefault().Name }).ToList(); if (usersFirstGameData.First().GameName == null) { // Get UserId, UserName, Game and Format DIBZ.Common.Model.ApplicationUser user = authLogic.GetUserById(userId); var nickName = user.NickName; DIBZ.Common.Model.GameCatalog selectedGame = new DIBZ.Common.Model.GameCatalog(); var offerLogic = LogicContext.Create <OfferLogic>(); selectedGame = await offerLogic.GetSelectedGameById(Convert.ToInt32(gameIds)); var gameName = selectedGame.Name; var gameFormat = selectedGame.Format.Name; if (notifierEmail.Count != 0) { // Email Sending to Specific Email address which is specified by DON. var notifierLastEmail = notifierEmail.FirstOrDefault().EmailAddress; EmailTemplateHelper templates = new EmailTemplateHelper(); EmailTemplateResponse emailTemplateResponse = new EmailTemplateResponse(); DIBZ.Common.Model.EmailNotification Email = new DIBZ.Common.Model.EmailNotification(); var emailTemplateLogic = LogicContext.Create <EmailTemplateLogic>(); emailTemplateResponse = await emailTemplateLogic.GetEmailTemplate(EmailType.Email, EmailContentType.UserFirstGame); templates.AddParam(DIBZ.Common.Model.Contants.AppUserNickName, nickName); templates.AddParam(DIBZ.Common.Model.Contants.GameCatalog_Name, gameName); templates.AddParam(DIBZ.Common.Model.Contants.GameFormat, gameFormat); var emailBody = templates.FillTemplate(emailTemplateResponse.Body); await emailTemplateLogic.SaveEmailNotification(notifierLastEmail, emailTemplateResponse.Title, emailBody, EmailType.Email, Priority.Low); EmailHelper.Email(notifierLastEmail, emailTemplateResponse.Title, emailBody); } } authLogic.AddGameIntoCollection(userId, gameIds); return(RedirectToAction("MyGames", new { currentPage, searchGame, formatId, categoryId })); } catch (Exception lex) { return(Json(new { IsSuccess = false, fail = lex.Message }, JsonRequestBehavior.AllowGet)); } }
public async Task <ActionResult> CreateOffer(string gameOfferId, string gameInReturnId) { DIBZDbContext context = new DIBZDbContext(); var notificationLogic = LogicContext.Create <NotificationLogic>(); var AuthLogic = LogicContext.Create <AuthLogic>(); var GameCatalog = LogicContext.Create <GameCatalogLogic>(); var emailTemplateLogic = LogicContext.Create <EmailTemplateLogic>(); List <DIBZ.Common.DTO.NotificationModel> notifications = new List <Common.DTO.NotificationModel>(); DIBZ.Common.Model.GameCatalog gameCatalog = new DIBZ.Common.Model.GameCatalog(); IEnumerable <DIBZ.Common.Model.ApplicationUser> allApplicationUsers = new List <DIBZ.Common.Model.ApplicationUser>(); DIBZ.Common.Model.EmailTemplate emailTemplate = new DIBZ.Common.Model.EmailTemplate(); EmailTemplateHelper templates = new EmailTemplateHelper(); EmailTemplateResponse emailTemplateResponce = new EmailTemplateResponse(); DIBZ.Common.Model.EmailNotification email = new DIBZ.Common.Model.EmailNotification(); List <int> offeredGameIds = gameOfferId.Split(',').Select(int.Parse).ToList(); List <int> returnedGameIds = new List <int>(); foreach (var offeredGameId in offeredGameIds) { AuthLogic.AddGameIntoCollection(CurrentLoginSession.ApplicationUser.Id, offeredGameId.ToString()); } if (!string.IsNullOrEmpty(gameInReturnId)) { returnedGameIds = gameInReturnId.Split(',').Select(int.Parse).ToList(); } var offerLogic = LogicContext.Create <OfferLogic>(); try { List <DIBZ.Common.Model.Offer> allOffers = new List <Common.Model.Offer>(); foreach (var offeredGameId in offeredGameIds) { if (returnedGameIds.Count > 0) { foreach (var returnedGameId in returnedGameIds) { allOffers.AddRange(CreateOfferForEachSelectedGameInReturn(offeredGameIds, returnedGameId)); } } else { OfferModel offerRequest = new OfferModel(); offerRequest.ApplicationUserId = CurrentLoginSession.ApplicationUserId.GetValueOrDefault(); offerRequest.GameCatalogId = Convert.ToInt32(offeredGameIds); offerLogic.AddUpdateOffer(offerRequest); } if (returnedGameIds.Count > 0) { NotificationModel notificationModel = new NotificationModel(); foreach (var offerId in allOffers) { gameCatalog = await GameCatalog.GetGameCatalogById(offerId.ReturnGameCatalogId.Value); //get all AppUsers By GameId allApplicationUsers = await AuthLogic.GetApplicationUserByGameId(offerId.ReturnGameCatalogId.Value); if (allApplicationUsers.Count() > 0) { foreach (var applicationUser in allApplicationUsers) { // we dont want to notify that user who create this offer if (applicationUser.Id != CurrentLoginSession.ApplicationUserId) { var additionalData = new { GameCatalogId = offeredGameIds, ReturnGameCatalogId = offerId.ReturnGameCatalogId.Value, ReturnImgpath = gameCatalog.imgpath, ReturnGameImageId = gameCatalog.GameImageId, OfferId = offerId.Id }; notificationModel.AdditionalData = Helpers.GetJson(additionalData); notificationModel.AppUserId = Convert.ToInt32(applicationUser.Id); //Channel like Android,Ios,Web notificationModel.Channel = Convert.ToInt32(DIBZ.Common.Model.Channel.Web); notificationModel.Content = "An offer is created for game " + gameCatalog.Name + ""; notificationModel.CreatedTime = DateTime.Now; notificationModel.LastError = ""; notificationModel.OfferIds = allOffers.Select(o => o.Id).ToList(); notificationModel.Status = Convert.ToInt32(DIBZ.Common.Model.NotificationStatus.Unseen); notificationModel.Title = "Create Offer"; notificationModel.NotificationType = Convert.ToInt32(DIBZ.Common.Model.NotificationType.Desktop); notificationModel.NotificationBusinessType = Convert.ToInt32(DIBZ.Common.Model.NotificationBusinessType.CreateOffer); //save notification in notification table var notification = await notificationLogic.AddNotification(notificationModel); // sent notification of offer creater to all users who have that game new DIBZ.Services.ServerNotificationService().CreateOffer(applicationUser.Id, notification.Id, notificationModel.Content, notificationModel.CreatedTime, notificationModel.AdditionalData); } } } } } } } catch (Exception ex) { LogHelper.LogError(ex.Message, ex); } return(RedirectToAction("MyAllOffers", "Offer")); }
public async Task <ActionResult> ChangeSwipStatus(int swapStatus, int offerId, int gameSwipWithId, int gameSwapPersonId, int offerPersonId, string failReasonVal, string failGameVal) { //declarations int failReasonIntValue = 0; int failGameIntVal = 0; string notificationMessage = string.Empty; DIBZ.Common.Model.Swap swap = new DIBZ.Common.Model.Swap(); DIBZ.Common.Model.Offer offer = new DIBZ.Common.Model.Offer(); DIBZ.Common.Model.ApplicationUser swapPerson = new DIBZ.Common.Model.ApplicationUser(); DIBZ.Common.Model.GameCatalog gameCatalog = new DIBZ.Common.Model.GameCatalog(); DIBZ.Common.Model.Notification notification = new DIBZ.Common.Model.Notification(); DIBZ.Common.Model.EmailTemplate emailTemplate = new DIBZ.Common.Model.EmailTemplate(); EmailTemplateHelper templates = new EmailTemplateHelper(); EmailTemplateResponse emailTemplateResponse = new EmailTemplateResponse(); DIBZ.Common.Model.EmailNotification email = new DIBZ.Common.Model.EmailNotification(); var scorecardLogic = LogicContext.Create <ScorecardLogic>(); var swapLogic = LogicContext.Create <SwapLogic>(); var offerLogic = LogicContext.Create <OfferLogic>(); var gameCatalogLogic = LogicContext.Create <GameCatalogLogic>(); var AuthLogic = LogicContext.Create <AuthLogic>(); var emailTemplateLogic = LogicContext.Create <EmailTemplateLogic>(); swap.SwapStatus = (DIBZ.Common.Model.SwapStatus)swapStatus; swap.OfferId = offerId; swap.GameSwapWithId = gameSwipWithId; swap.GameSwapPsersonId = gameSwapPersonId; swap.IsActive = true; swap.UpdatedTime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:sss")); //get offer by Id to get Id of Offer Creater person offer = await offerLogic.GetOfferById(offerId); //add swap swap = await swapLogic.AddSwap(swap); //get applicationUserBy applicationUserID swapPerson = await AuthLogic.GetApplicationUserById(swap.GameSwapPsersonId); //get gamecatalog by gameCatalogId gameCatalog = await gameCatalogLogic.GetGameCatalogById(swap.GameSwapWithId); if (swap != null) { var status = (DIBZ.Common.Model.SwapStatus)swapStatus; if (status == DIBZ.Common.Model.SwapStatus.Game1_NoShow) { //if it is SentGame case so update status of only one party at one one await scorecardLogic.UpdateScoreCardByAppUserId(offer.ApplicationUserId, swapStatus, failReasonIntValue, false); //Save notification notificationMessage = "Your " + swap.Offer.GameCatalog.Name + " game hasn't been received with in 5 day, Thank you."; int gameImageId = swap.Offer.GameCatalog.GameImageId; notification = await SaveNotificationForSwapAction(swap, swap.Offer.ApplicationUserId, gameImageId, notificationMessage); //sent notification to user new DIBZ.Services.ServerNotificationService().SwapAction(notification.AppUserId, notification.AdditionalData); //create email template emailTemplateResponse = await emailTemplateLogic.GetEmailTemplate(EmailType.Email, EmailContentType.Game_1_NoShow); templates.AddParam(DIBZ.Common.Model.Contants.AppUserNickName, swap.Offer.ApplicationUser.NickName); templates.AddParam(DIBZ.Common.Model.Contants.GameCatalog_Name, swap.Offer.GameCatalog.Name); templates.AddParam(DIBZ.Common.Model.Contants.GameFormat, swap.Offer.GameCatalog.Format.Name); templates.AddParam(DIBZ.Common.Model.Contants.GameCatalog_Name_Swapper, gameCatalog.Name); templates.AddParam(DIBZ.Common.Model.Contants.GameFormatSwapper, gameCatalog.Format.Name); templates.AddParam(DIBZ.Common.Model.Contants.UrlContactUs, string.Format("<a href='{0}'>here</a>", hostName + "/Dashboard/ContactUs")); //templates.AddParam(DIBZ.Common.Model.Contants.GameCatalog_Name, swap.Offer.GameCatalog.Name); var emailBody = templates.FillTemplate(emailTemplateResponse.Body); //save email data in table await emailTemplateLogic.SaveEmailNotification(swap.Offer.ApplicationUser.Email, emailTemplateResponse.Title, emailBody, EmailType.Email, Priority.Low); EmailHelper.Email(swap.Offer.ApplicationUser.Email, emailTemplateResponse.Title, emailBody); } else if (status == DIBZ.Common.Model.SwapStatus.Game2_NoShow) { //if it is SentGame case so update status of only one party at one one await scorecardLogic.UpdateScoreCardByAppUserId(swap.GameSwapPsersonId, swapStatus, failReasonIntValue, false); //Save notification notificationMessage = "Your " + swap.Offer.ReturnGameCatalog.Name + " game hasn't been received with in 5 day, Thank you."; int gameImageId = swap.Offer.ReturnGameCatalog.GameImageId; notification = await SaveNotificationForSwapAction(swap, swap.GameSwapPsersonId, gameImageId, notificationMessage); //sent notification to user new DIBZ.Services.ServerNotificationService().SwapAction(notification.AppUserId, notification.AdditionalData); //create email template emailTemplateResponse = await emailTemplateLogic.GetEmailTemplate(EmailType.Email, EmailContentType.Game_2_NoShow); templates.AddParam(DIBZ.Common.Model.Contants.AppUserNickName, swap.GameSwapPserson.NickName); templates.AddParam(DIBZ.Common.Model.Contants.GameCatalog_Name, swap.Offer.GameCatalog.Name); templates.AddParam(DIBZ.Common.Model.Contants.GameFormat, swap.Offer.GameCatalog.Format.Name); templates.AddParam(DIBZ.Common.Model.Contants.GameCatalog_Name_Swapper, gameCatalog.Name); templates.AddParam(DIBZ.Common.Model.Contants.GameFormatSwapper, gameCatalog.Format.Name); templates.AddParam(DIBZ.Common.Model.Contants.UrlContactUs, string.Format("<a href='{0}'>here</a>", hostName + "/Dashboard/ContactUs")); //templates.AddParam(DIBZ.Common.Model.Contants.GameCatalog_Name, swap.Offer.ReturnGameCatalog.Name); var emailBody = templates.FillTemplate(emailTemplateResponse.Body); //save email data in table await emailTemplateLogic.SaveEmailNotification(swap.GameSwapPserson.Email, emailTemplateResponse.Title, emailBody, EmailType.Email, Priority.Low); EmailHelper.Email(swap.GameSwapPserson.Email, emailTemplateResponse.Title, emailBody); } else if (status == DIBZ.Common.Model.SwapStatus.All_NoShow) { //get email template emailTemplateResponse = await emailTemplateLogic.GetEmailTemplate(EmailType.Email, EmailContentType.All_NoShow); //Save notification notificationMessage = "Your " + swap.Offer.GameCatalog.Name + " game hasn't been received with in 5 day, Thank you."; int offerGameImageId = swap.Offer.GameCatalog.GameImageId; notification = await SaveNotificationForSwapAction(swap, swap.Offer.ApplicationUserId, offerGameImageId, notificationMessage); //sent notification to user new DIBZ.Services.ServerNotificationService().SwapAction(notification.AppUserId, notification.AdditionalData); templates.AddParam(DIBZ.Common.Model.Contants.AppUserNickName, swap.Offer.ApplicationUser.NickName); templates.AddParam(DIBZ.Common.Model.Contants.GameCatalog_Name, swap.Offer.GameCatalog.Name); templates.AddParam(DIBZ.Common.Model.Contants.GameFormat, swap.Offer.GameCatalog.Format.Name); templates.AddParam(DIBZ.Common.Model.Contants.GameCatalog_Name_Swapper, swap.Offer.ReturnGameCatalog.Name); templates.AddParam(DIBZ.Common.Model.Contants.GameFormatSwapper, swap.Offer.ReturnGameCatalog.Format.Name); templates.AddParam(DIBZ.Common.Model.Contants.UrlContactUs, string.Format("<a href='{0}'>here</a>", hostName + "/Dashboard/ContactUs")); //templates.AddParam(DIBZ.Common.Model.Contants.GameCatalog_Name, swap.Offer.GameCatalog.Name); var emailBodyOfferCreator = templates.FillTemplate(emailTemplateResponse.Body); //save email data in table await emailTemplateLogic.SaveEmailNotification(swap.Offer.ApplicationUser.Email, emailTemplateResponse.Title, emailBodyOfferCreator, EmailType.Email, Priority.Low); EmailHelper.Email(swap.Offer.ApplicationUser.Email, emailTemplateResponse.Title, emailBodyOfferCreator); //Save notification notificationMessage = "Your " + swap.Offer.ReturnGameCatalog.Name + " game hasn't been received with in 5 day, Thank you."; int gameImageId = swap.Offer.ReturnGameCatalog.GameImageId; notification = await SaveNotificationForSwapAction(swap, swap.GameSwapPsersonId, gameImageId, notificationMessage); //sent notification to user new DIBZ.Services.ServerNotificationService().SwapAction(notification.AppUserId, notification.AdditionalData); //create email template EmailTemplateHelper template2 = new EmailTemplateHelper(); EmailTemplateResponse emailTemplateResponse2 = new EmailTemplateResponse(); emailTemplateResponse2 = await emailTemplateLogic.GetEmailTemplate(EmailType.Email, EmailContentType.All_NoShow); template2.AddParam(DIBZ.Common.Model.Contants.AppUserNickName, swap.GameSwapPserson.NickName); template2.AddParam(DIBZ.Common.Model.Contants.GameCatalog_Name, swap.Offer.ReturnGameCatalog.Name); template2.AddParam(DIBZ.Common.Model.Contants.GameFormat, swap.Offer.ReturnGameCatalog.Format.Name); template2.AddParam(DIBZ.Common.Model.Contants.GameCatalog_Name_Swapper, swap.Offer.GameCatalog.Name); template2.AddParam(DIBZ.Common.Model.Contants.GameFormatSwapper, swap.Offer.GameCatalog.Format.Name); template2.AddParam(DIBZ.Common.Model.Contants.UrlContactUs, string.Format("<a href='{0}'>here</a>", hostName + "/Dashboard/ContactUs")); var emailBodyGameSwapPerson = template2.FillTemplate(emailTemplateResponse2.Body); //save email data in table await emailTemplateLogic.SaveEmailNotification(swap.GameSwapPserson.Email, emailTemplateResponse2.Title, emailBodyGameSwapPerson, EmailType.Email, Priority.Low); EmailHelper.Email(swap.GameSwapPserson.Email, emailTemplateResponse2.Title, emailBodyGameSwapPerson); } else if (status == DIBZ.Common.Model.SwapStatus.Game1_Received) { //if it is SentGame case so update status of only one party at one one await scorecardLogic.UpdateScoreCardByAppUserId(offer.ApplicationUserId, swapStatus, failReasonIntValue, true); //Save notification notificationMessage = "Your" + swap.Offer.GameCatalog.Name + "game has been received! Thank you."; int gameImageId = swap.Offer.GameCatalog.GameImageId; notification = await SaveNotificationForSwapAction(swap, swap.Offer.ApplicationUserId, gameImageId, notificationMessage); //sent notification to user new DIBZ.Services.ServerNotificationService().SwapAction(notification.AppUserId, notification.AdditionalData); //create email template emailTemplateResponse = await emailTemplateLogic.GetEmailTemplate(EmailType.Email, EmailContentType.Game_1_Recieved); templates.AddParam(DIBZ.Common.Model.Contants.AppUserNickName, swap.Offer.ApplicationUser.NickName); templates.AddParam(DIBZ.Common.Model.Contants.GameCatalog_Name, swap.Offer.GameCatalog.Name); templates.AddParam(DIBZ.Common.Model.Contants.GameFormat, swap.Offer.GameCatalog.Format.Name); templates.AddParam(DIBZ.Common.Model.Contants.GameCatalog_Name_Swapper, swap.Offer.ReturnGameCatalog.Name); templates.AddParam(DIBZ.Common.Model.Contants.GameFormatSwapper, swap.Offer.ReturnGameCatalog.Format.Name); templates.AddParam(DIBZ.Common.Model.Contants.UrlContactUs, string.Format("<a href='{0}'>here</a>", hostName + "/Dashboard/ContactUs")); var emailBody = templates.FillTemplate(emailTemplateResponse.Body); LogHelper.LogInfo("sending email..."); LogHelper.LogInfo("UrlContactUsPage: " + ConfigurationManager.AppSettings["UrlContactUsPage"]); //save email data in table await emailTemplateLogic.SaveEmailNotification(swap.Offer.ApplicationUser.Email, emailTemplateResponse.Title, emailBody, EmailType.Email, Priority.Low); EmailHelper.Email(swap.Offer.ApplicationUser.Email, emailTemplateResponse.Title, emailBody); //sent email // await EmailHelper.SendEmail(swap.Offer.ApplicationUser.Email,EmailTemplateResponce.Title, emailBody); } else if (status == DIBZ.Common.Model.SwapStatus.Game2_Received) { //if it is SentGame case so update status of only one party at one one await scorecardLogic.UpdateScoreCardByAppUserId(gameSwapPersonId, swapStatus, failReasonIntValue, true); //Save notification notificationMessage = "Your " + gameCatalog.Name + " game has been received! Thank you."; int gameImageId = gameCatalog.GameImageId; notification = await SaveNotificationForSwapAction(swap, swap.GameSwapPsersonId, gameImageId, notificationMessage); //sent notification to user new DIBZ.Services.ServerNotificationService().SwapAction(notification.AppUserId, notification.AdditionalData); //create email template emailTemplateResponse = await emailTemplateLogic.GetEmailTemplate(DIBZ.Common.Model.EmailType.Email, DIBZ.Common.Model.EmailContentType.Game_2_Recieved); templates.AddParam(DIBZ.Common.Model.Contants.AppUserNickName, swap.GameSwapPserson.NickName); templates.AddParam(DIBZ.Common.Model.Contants.GameCatalog_Name, gameCatalog.Name); templates.AddParam(DIBZ.Common.Model.Contants.GameFormat, gameCatalog.Format.Name); templates.AddParam(DIBZ.Common.Model.Contants.GameCatalog_Name_Swapper, swap.Offer.GameCatalog.Name); templates.AddParam(DIBZ.Common.Model.Contants.GameFormatSwapper, swap.Offer.GameCatalog.Format.Name); templates.AddParam(DIBZ.Common.Model.Contants.UrlContactUs, string.Format("<a href='{0}'>here</a>", hostName + "/Dashboard/ContactUs")); //templates.AddParam(DIBZ.Common.Model.Contants.GameCatalog_Name, gameCatalog.Name); var emailBody = templates.FillTemplate(emailTemplateResponse.Body); LogHelper.LogInfo("sending email..."); LogHelper.LogInfo("UrlContactUsPage: " + ConfigurationManager.AppSettings["UrlContactUsPage"]); //save email data in table await emailTemplateLogic.SaveEmailNotification(swap.GameSwapPserson.Email, emailTemplateResponse.Title, emailBody, EmailType.Email, Priority.Low); EmailHelper.Email(swap.GameSwapPserson.Email, emailTemplateResponse.Title, emailBody); } else { if (failReasonVal != "" || failReasonVal == string.Empty) { failReasonIntValue = ConversionHelper.SafeConvertToInt32(failReasonVal); } if (failGameVal != "" || failGameVal == string.Empty) { failGameIntVal = ConversionHelper.SafeConvertToInt32(failGameVal); } //if is not a SentGame case so update status of both parties if (status != DIBZ.Common.Model.SwapStatus.Test_Fail) { await scorecardLogic.UpdateScoreCardByAppUserId(offer.ApplicationUserId, swapStatus, failReasonIntValue, false); await scorecardLogic.UpdateScoreCardByAppUserId(gameSwapPersonId, swapStatus, failReasonIntValue, false); } if (status == DIBZ.Common.Model.SwapStatus.Test_Pass) { notificationMessage = "Congratulation! your swap test has been passed!"; } if (status == DIBZ.Common.Model.SwapStatus.Test_Fail) { string failGameName = string.Empty; if (failGameIntVal == (int)DIBZ.Common.Model.SwapStatus.Game1_Received) { //get OfferCreater GameName failGameName = swap.Offer.GameCatalog.Name; //update score card only offer creater await scorecardLogic.UpdateScoreCardByAppUserId(offer.ApplicationUserId, swapStatus, failReasonIntValue, false); } if (failGameIntVal == (int)DIBZ.Common.Model.SwapStatus.Game2_Received) { //get SwapPerson GameName failGameName = gameCatalog.Name; //update score card only SwapPerson await scorecardLogic.UpdateScoreCardByAppUserId(gameSwapPersonId, swapStatus, failReasonIntValue, false); } if (failReasonIntValue == (int)DIBZ.Common.Model.FailCasses.DiscScratched) { notificationMessage = "Sorry! " + failGameName + " has been failed due to discScratched!"; } else if (failReasonIntValue == (int)DIBZ.Common.Model.FailCasses.CaseOrInstructionsInPoorCondition) { notificationMessage = "Sorry! " + failGameName + " has been failed due to case/instruction in poor condition!"; } else if (failReasonIntValue == (int)DIBZ.Common.Model.FailCasses.GameFailedTesting) { notificationMessage = "Sorry! " + failGameName + " has been failed due to game failed testing!"; } } if (status == DIBZ.Common.Model.SwapStatus.Dispatched) { LogHelper.LogInfo("swaps status set to dispatach."); // removing game from offer creator's collection. await gameCatalogLogic.RemoveGameFromCollectionOnDispatch(offer.ApplicationUserId, offer.GameCatalogId); // removing game from swapper's collection. await gameCatalogLogic.RemoveGameFromCollectionOnDispatch(swap.GameSwapPsersonId, swap.GameSwapWithId); notificationMessage = "Congratulation! swap has been Successfuly dibz!"; } if (status == DIBZ.Common.Model.SwapStatus.Test_Pass || status == DIBZ.Common.Model.SwapStatus.Test_Fail || status == DIBZ.Common.Model.SwapStatus.Dispatched) { int gameImageId = swap.Offer.GameCatalog.GameImageId; int swapperGameImageId = swap.GameSwapWithId; //Save notification to one User notification = await SaveNotificationForSwapAction(swap, swap.Offer.ApplicationUserId, gameImageId, notificationMessage); //sent notification to One user new DIBZ.Services.ServerNotificationService().SwapAction(notification.AppUserId, notification.AdditionalData); //Save notification to anotherUSerr notification = await SaveNotificationForSwapAction(swap, swap.GameSwapPsersonId, swapperGameImageId, notificationMessage); // sent notification to anotherUSer new DIBZ.Services.ServerNotificationService().SwapAction(notification.AppUserId, notification.AdditionalData); //sent Bcc email List <string> emailList = new List <string>(); emailList.Add(swapPerson.Email); emailList.Add(swap.Offer.ApplicationUser.Email); if (status == SwapStatus.Test_Pass) { //create email template for offerrer emailTemplateResponse = await emailTemplateLogic.GetEmailTemplate(EmailType.Email, EmailContentType.Test_Pass); templates.AddParam(DIBZ.Common.Model.Contants.AppUserNickName, swap.Offer.ApplicationUser.NickName); templates.AddParam(DIBZ.Common.Model.Contants.GameCatalog_Name, swap.Offer.GameCatalog.Name); templates.AddParam(DIBZ.Common.Model.Contants.GameFormat, swap.Offer.GameCatalog.Format.Name); templates.AddParam(DIBZ.Common.Model.Contants.GameCatalog_Name_Swapper, swap.Offer.ReturnGameCatalog.Name); templates.AddParam(DIBZ.Common.Model.Contants.GameFormatSwapper, swap.Offer.ReturnGameCatalog.Format.Name); templates.AddParam(DIBZ.Common.Model.Contants.UrlContactUs, string.Format("<a href='{0}'>here</a>", hostName + "/Dashboard/ContactUs")); var emailBody = templates.FillTemplate(emailTemplateResponse.Body); //save email data in table await emailTemplateLogic.SaveEmailNotification(swap.Offer.ApplicationUser.Email, emailTemplateResponse.Title, emailBody, EmailType.Email, Priority.Low); EmailHelper.Email(swap.Offer.ApplicationUser.Email, emailTemplateResponse.Title, emailBody); //create template for swapper EmailTemplateResponse emailTemplateResponse2 = new EmailTemplateResponse(); EmailTemplateHelper template2 = new EmailTemplateHelper(); emailTemplateResponse2 = await emailTemplateLogic.GetEmailTemplate(EmailType.Email, EmailContentType.Test_Pass); template2.AddParam(DIBZ.Common.Model.Contants.AppUserNickName, swap.GameSwapPserson.NickName); template2.AddParam(DIBZ.Common.Model.Contants.GameCatalog_Name, swap.GameSwapWith.Name); template2.AddParam(DIBZ.Common.Model.Contants.GameFormat, swap.GameSwapWith.Format.Name); template2.AddParam(DIBZ.Common.Model.Contants.GameCatalog_Name_Swapper, swap.Offer.GameCatalog.Name); template2.AddParam(DIBZ.Common.Model.Contants.GameFormatSwapper, swap.Offer.GameCatalog.Format.Name); template2.AddParam(DIBZ.Common.Model.Contants.UrlContactUs, string.Format("<a href='{0}'>here</a>", hostName + "/Dashboard/ContactUs")); var emailBodySwapper = template2.FillTemplate(emailTemplateResponse2.Body); //save email data in table await emailTemplateLogic.SaveEmailNotification(swapPerson.Email, emailTemplateResponse2.Title, emailBodySwapper, EmailType.Email, Priority.Low); EmailHelper.Email(swapPerson.Email, emailTemplateResponse2.Title, emailBodySwapper); } else if (status == SwapStatus.Test_Fail) { if (failGameIntVal == (int)DIBZ.Common.Model.SwapStatus.Game1_Received) { //create email template game1 test failed emailTemplateResponse = await emailTemplateLogic.GetEmailTemplate(EmailType.Email, EmailContentType.Test_Fail); templates.AddParam(DIBZ.Common.Model.Contants.AppUserNickName, swap.Offer.ApplicationUser.NickName); templates.AddParam(DIBZ.Common.Model.Contants.GameCatalog_Name, swap.Offer.GameCatalog.Name); templates.AddParam(DIBZ.Common.Model.Contants.GameFormat, swap.Offer.GameCatalog.Format.Name); if (failReasonIntValue == (int)DIBZ.Common.Model.FailCasses.DiscScratched) { notificationMessage = "Sorry! " + swap.Offer.GameCatalog.Name + " has been failed due to discScratched!"; templates.AddParam(DIBZ.Common.Model.Contants.FailReason, notificationMessage); } else if (failReasonIntValue == (int)DIBZ.Common.Model.FailCasses.CaseOrInstructionsInPoorCondition) { notificationMessage = "Sorry! " + swap.Offer.GameCatalog.Name + " has been failed due to case/instruction in poor condition!"; templates.AddParam(DIBZ.Common.Model.Contants.FailReason, notificationMessage); } else if (failReasonIntValue == (int)DIBZ.Common.Model.FailCasses.GameFailedTesting) { notificationMessage = "Sorry! " + swap.Offer.GameCatalog.Name + " has been failed due to game failed testing!"; templates.AddParam(DIBZ.Common.Model.Contants.FailReason, notificationMessage); } templates.AddParam(DIBZ.Common.Model.Contants.GameCatalog_Name_Swapper, gameCatalog.Name); templates.AddParam(DIBZ.Common.Model.Contants.GameFormatSwapper, gameCatalog.Format.Name); templates.AddParam(DIBZ.Common.Model.Contants.UrlContactUs, string.Format("<a href='{0}'>here</a>", hostName + "/Dashboard/ContactUs")); var emailBody = templates.FillTemplate(emailTemplateResponse.Body); //save email data in table await emailTemplateLogic.SaveEmailNotification(offer.ApplicationUser.Email, emailTemplateResponse.Title, emailBody, EmailType.Email, Priority.Low); EmailHelper.Email(offer.ApplicationUser.Email, emailTemplateResponse.Title, emailBody); } else { //create email template game2 test failed EmailTemplateResponse emailTemplateResponse2 = new EmailTemplateResponse(); EmailTemplateHelper template2 = new EmailTemplateHelper(); emailTemplateResponse2 = await emailTemplateLogic.GetEmailTemplate(EmailType.Email, EmailContentType.Test_Fail); template2.AddParam(DIBZ.Common.Model.Contants.AppUserNickName, swap.GameSwapPserson.NickName); template2.AddParam(DIBZ.Common.Model.Contants.GameCatalog_Name_Swapper, gameCatalog.Name); template2.AddParam(DIBZ.Common.Model.Contants.GameFormatSwapper, gameCatalog.Format.Name); template2.AddParam(DIBZ.Common.Model.Contants.GameCatalog_Name, swap.Offer.GameCatalog.Name); template2.AddParam(DIBZ.Common.Model.Contants.GameFormat, swap.Offer.GameCatalog.Format.Name); template2.AddParam(DIBZ.Common.Model.Contants.UrlContactUs, string.Format("<a href='{0}'>here</a>", hostName + "/Dashboard/ContactUs")); var emailBody = template2.FillTemplate(emailTemplateResponse2.Body); //save email data in table await emailTemplateLogic.SaveEmailNotification(swap.GameSwapPserson.Email, emailTemplateResponse2.Title, emailBody, EmailType.Email, Priority.Low); EmailHelper.Email(swap.GameSwapPserson.Email, emailTemplateResponse2.Title, emailBody); } } else if (status == SwapStatus.Dispatched) { //create email template for Offerrer emailTemplateResponse = await emailTemplateLogic.GetEmailTemplate(EmailType.Email, EmailContentType.Dispatch); templates.AddParam(DIBZ.Common.Model.Contants.AppUserNickName, swap.Offer.ApplicationUser.NickName); templates.AddParam(DIBZ.Common.Model.Contants.GameCatalog_Name, swap.Offer.GameCatalog.Name); templates.AddParam(DIBZ.Common.Model.Contants.GameFormat, swap.Offer.GameCatalog.Format.Name); templates.AddParam(DIBZ.Common.Model.Contants.GameCatalog_Name_Swapper, swap.Offer.ReturnGameCatalog.Name); templates.AddParam(DIBZ.Common.Model.Contants.GameFormatSwapper, swap.Offer.ReturnGameCatalog.Format.Name); templates.AddParam(DIBZ.Common.Model.Contants.GameCatalog_Name_Dispatch, swap.Offer.ReturnGameCatalog.Name); templates.AddParam(DIBZ.Common.Model.Contants.GameFormatSwapper_Dispatch, swap.Offer.ReturnGameCatalog.Format.Name); templates.AddParam(DIBZ.Common.Model.Contants.AppUserAddress, swap.Offer.ApplicationUser.Address); templates.AddParam(DIBZ.Common.Model.Contants.UrlContactUs, string.Format("<a href='{0}'>here</a>", hostName + "/Dashboard/ContactUs")); var emailBody = templates.FillTemplate(emailTemplateResponse.Body); //save email data in table await emailTemplateLogic.SaveEmailNotification(swap.Offer.ApplicationUser.Email, emailTemplateResponse.Title, emailBody, EmailType.Email, Priority.Low); EmailHelper.Email(swap.Offer.ApplicationUser.Email, emailTemplateResponse.Title, emailBody); //create email template for Swapper EmailTemplateResponse emailTemplateResponse2 = new EmailTemplateResponse(); EmailTemplateHelper template2 = new EmailTemplateHelper(); emailTemplateResponse2 = await emailTemplateLogic.GetEmailTemplate(EmailType.Email, EmailContentType.Dispatch); template2.AddParam(DIBZ.Common.Model.Contants.AppUserNickName, swap.GameSwapPserson.NickName); template2.AddParam(DIBZ.Common.Model.Contants.GameCatalog_Name, swap.GameSwapWith.Name); template2.AddParam(DIBZ.Common.Model.Contants.GameFormat, swap.GameSwapWith.Format.Name); template2.AddParam(DIBZ.Common.Model.Contants.GameCatalog_Name_Swapper, swap.Offer.GameCatalog.Name); template2.AddParam(DIBZ.Common.Model.Contants.GameFormatSwapper, swap.Offer.GameCatalog.Format.Name); template2.AddParam(DIBZ.Common.Model.Contants.GameCatalog_Name_Dispatch, swap.Offer.GameCatalog.Name); template2.AddParam(DIBZ.Common.Model.Contants.GameFormatSwapper_Dispatch, swap.Offer.GameCatalog.Format.Name); template2.AddParam(DIBZ.Common.Model.Contants.AppUserAddress, swap.GameSwapPserson.Address); template2.AddParam(DIBZ.Common.Model.Contants.UrlContactUs, string.Format("<a href='{0}'>here</a>", hostName + "/Dashboard/ContactUs")); var emailBodySwapper = template2.FillTemplate(emailTemplateResponse2.Body); //save email data in table await emailTemplateLogic.SaveEmailNotification(swapPerson.Email, emailTemplateResponse2.Title, emailBodySwapper, EmailType.Email, Priority.Low); EmailHelper.Email(swapPerson.Email, emailTemplateResponse2.Title, emailBodySwapper); } // await EmailHelper.SendEmailBcc(emailList, "Dibz swap status update", notificationMessage); } } return(Json(new { IsSuccess = true, data = string.Empty }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { IsSuccess = false, fail = "Some thing wrong!" }, JsonRequestBehavior.AllowGet)); } }