public int PreviousCardStatus(ref UserPostCardRecipient model) { int status = (int)CardStatusTypes.InProgress; if (model.IsApproved == true) { status = (int)CardStatusTypes.InProgress; } if (model.IsRejected == true) { status = (int)CardStatusTypes.InProgress; } if (model.IsError == true) { status = (int)CardStatusTypes.InProgress; } if (model.IsCompleted == true && model.IsRejected == true) { status = (int)CardStatusTypes.Completed; } if (model.IsCompleted == true && model.IsError == true) { status = (int)CardStatusTypes.Completed; } if (model.IsApproved == true && model.IsError == true && model.IsCompleted == false) { status = (int)CardStatusTypes.Approved; } return(status); }
public ReceiptentOrder(UserPostCardRecipient obj) { this.OrderID = obj.UserPostCardID ?? 0; this.DatePlaced = Convert.ToDateTime(obj.UserPostCard.AddedOn).ToString("hh:mm tt dd MMM yyyy"); this.DueTo = Convert.ToDateTime(obj.UserPostCard.ShipmentDate).ToString("hh:mm tt dd MMM yyyy"); this.BackImage = obj.UserPostCard.CardBackPath; this.FrontImage = obj.UserPostCard.CardFrontPath; this.UserName = obj.UserPostCard.User.FirstName + " " + obj.UserPostCard.User.LastName; this.ReceiptentName = obj.Name; this.ReceiptentAddress = obj.Address + ", " + obj.City + ", " + obj.State + ", " + obj.Zip + ", " + obj.Country; }
ActionOutput <PostCardResultModel> IEditorManager.AddUpdatePostCard(AddUpdateImageEditorModel model) { IUserManager _um = new UserManager(); var user = Context.Users.FirstOrDefault(x => x.UserID == model.UserID); var userCardsLeft = user.CardsCount; var id = 0; var resultObject = new PostCardResultModel(); var message = ""; if (userCardsLeft > 0) { try { if (model.IsCopyCard) { model.ID = 0; } if (model.ID > 0) { var PostCard = Context.UserPostCards.Where(z => z.ID == model.ID && z.IsDeleted != true).FirstOrDefault(); var rootPath = AttacmentsPath.UserProfileImages + user.FirstName.Replace(" ", "") + "-" + user.UserID + "/PostCards/"; //delete the existed files if (!string.IsNullOrEmpty(PostCard.CardFrontPath)) { var file = PostCard.CardFrontPath.Split('/')[5]; var path = HttpContext.Current.Server.MapPath(rootPath + file); if (File.Exists(path)) { File.Delete(path); } } if (!string.IsNullOrEmpty(PostCard.CardBackPath)) { var file = PostCard.CardBackPath.Split('/')[5]; var path = HttpContext.Current.Server.MapPath(rootPath + file); if (File.Exists(path)) { File.Delete(path); } } if (!string.IsNullOrEmpty(PostCard.CardBackPathWithIFrame)) { var file = PostCard.CardBackPathWithIFrame.Split('/')[5]; var path = HttpContext.Current.Server.MapPath(rootPath + file); if (File.Exists(path)) { File.Delete(path); } } PostCard = Mapper.Map <AddUpdateImageEditorModel, UserPostCard>(model, PostCard); if (PostCard.IsOrderPlaced == true) { PostCard.IsOrderPlaced = true; PostCard.OrderPlacedOn = DateTime.UtcNow; IEmailManager email = new EmailManager(); email.SendOrderStatusToAdmin("Placed", user); } if (!string.IsNullOrEmpty(model.CardFrontJson)) { var frontUID = Guid.NewGuid().ToString(); var imageFront = Utilities.Base64ToImage(model.CardFront); PostCard.ShipmentDate = model.ShipmentDate; var frontImageName = Guid.NewGuid().ToString() + "-front" + ".png"; if (!Directory.Exists(rootPath)) { Directory.CreateDirectory(HttpContext.Current.Server.MapPath(rootPath)); } imageFront.Save(HttpContext.Current.Server.MapPath(rootPath) + frontImageName); PostCard.CardFrontPath = rootPath + frontImageName; PostCard.CardFront = null; } if (!string.IsNullOrEmpty(model.CardBackJson)) { var backUID = Guid.NewGuid().ToString(); var imageBack = Utilities.Base64ToImage(model.CardBack); var backImageName = Guid.NewGuid().ToString() + "-back" + ".png"; if (!Directory.Exists(rootPath)) { Directory.CreateDirectory(HttpContext.Current.Server.MapPath(rootPath)); } imageBack.Save(HttpContext.Current.Server.MapPath(rootPath) + backImageName); PostCard.CardBackPath = rootPath + backImageName; PostCard.CardBack = null; } if (!string.IsNullOrEmpty(model.CardBackJsonWithIFrame)) { var backframeUID = Guid.NewGuid().ToString(); var imageBackWithFrame = Utilities.Base64ToImage(model.CardBackWithFrame); var backImageName = Guid.NewGuid().ToString() + "-backWithFrame" + ".png"; if (!Directory.Exists(rootPath)) { Directory.CreateDirectory(HttpContext.Current.Server.MapPath(rootPath)); } imageBackWithFrame.Save(HttpContext.Current.Server.MapPath(rootPath) + backImageName); PostCard.CardBackPathWithIFrame = rootPath + backImageName; } if (PostCard.UserPostCardRecipients != null && PostCard.UserPostCardRecipients.Count > 0) { foreach (var item in PostCard.UserPostCardRecipients) { Context.UserHistories.RemoveRange(item.UserHistories); } } Context.UserPostCardRecipients.RemoveRange(PostCard.UserPostCardRecipients); if (model.Recipients.Count > 0) { foreach (var item in model.Recipients) { if (user.CardsCount > 0) { var recipient = new UserPostCardRecipient(); recipient = Mapper.Map <UserRecipientModel, UserPostCardRecipient>(item, recipient); recipient.FKUserAddressBookId = item.ID; recipient.AddedOn = DateTime.UtcNow; recipient.IsCompleted = false; recipient.IsApproved = false; recipient.CardStatus = (int)CardStatusTypes.InProgress; PostCard.UserPostCardRecipients.Add(recipient); recipient.UserHistories.Add(new UserHistory() { UserFK = model.UserID, Type = "Order Placed", TokenChange = "-1", AddedOn = DateTime.UtcNow }); if (model.IsOrderPlaced) { user.CardsCount--; //27-feb-2018 } } else { return(new ActionOutput <PostCardResultModel> { Status = ActionStatus.Error, Message = "Your pending tokens are less than the recipient you added. Please add tokens for new orders." }); } } } PostCard.UpdatedOn = DateTime.UtcNow; // Context.UserPostCards.Add(PostCard); // Context.UserPostCardRecipients.AddRange(PostCard.UserPostCardRecipients); message = "Postcard details updated successfully."; id = PostCard.ID; Context.SaveChanges(); resultObject = new PostCardResultModel(PostCard); } else { var rootPath = AttacmentsPath.UserProfileImages + user.FirstName.Replace(" ", "") + "-" + user.UserID + "/PostCards/"; var postCard = new UserPostCard(); UserPostCard book = Mapper.Map <AddUpdateImageEditorModel, UserPostCard>(model); book.UpdatedOn = DateTime.UtcNow; book.AddedOn = DateTime.UtcNow; if (book.IsOrderPlaced == true) { book.IsOrderPlaced = true; book.OrderPlacedOn = DateTime.UtcNow; IEmailManager email = new EmailManager(); email.SendOrderStatusToAdmin("Placed", user); } book.ShipmentDate = model.ShipmentDate; book.IsDeleted = false; if (!string.IsNullOrEmpty(model.CardFrontJson)) { var frontUID = Guid.NewGuid().ToString(); var imageFront = Utilities.Base64ToImage(model.CardFront); var frontImageName = Guid.NewGuid().ToString() + "-front" + ".png"; if (!Directory.Exists(rootPath)) { Directory.CreateDirectory(HttpContext.Current.Server.MapPath(rootPath)); } imageFront.Save(HttpContext.Current.Server.MapPath(rootPath) + frontImageName); book.CardFrontPath = rootPath + frontImageName; book.CardFront = null; } if (!string.IsNullOrEmpty(model.CardBackJson)) { var backUID = Guid.NewGuid().ToString(); var imageBack = Utilities.Base64ToImage(model.CardBack); var backImageName = Guid.NewGuid().ToString() + "-back" + ".png"; if (!Directory.Exists(rootPath)) { Directory.CreateDirectory(HttpContext.Current.Server.MapPath(rootPath)); } imageBack.Save(HttpContext.Current.Server.MapPath(rootPath) + backImageName); book.CardBackPath = rootPath + backImageName; book.CardBack = null; } if (!string.IsNullOrEmpty(model.CardBackJsonWithIFrame)) { var backframeUID = Guid.NewGuid().ToString(); var imageBackWithFrame = Utilities.Base64ToImage(model.CardBackWithFrame); var backImageName = Guid.NewGuid().ToString() + "-backWithFrame" + ".png"; if (!Directory.Exists(rootPath)) { Directory.CreateDirectory(HttpContext.Current.Server.MapPath(rootPath)); } imageBackWithFrame.Save(HttpContext.Current.Server.MapPath(rootPath) + backImageName); book.CardBackPathWithIFrame = rootPath + backImageName; } if (model.Recipients.Count > 0) { foreach (var item in model.Recipients) { if (user.CardsCount > 0) { var recipient = new UserPostCardRecipient(); recipient = Mapper.Map <UserRecipientModel, UserPostCardRecipient>(item, recipient); recipient.FKUserAddressBookId = item.ID; recipient.AddedOn = DateTime.UtcNow; recipient.IsCompleted = false; recipient.IsApproved = false; recipient.CardStatus = (int)CardStatusTypes.InProgress; book.UserPostCardRecipients.Add(recipient); recipient.UserHistories.Add(new UserHistory() { UserFK = model.UserID, Type = "Order Placed", TokenChange = "-1", AddedOn = DateTime.UtcNow }); if (model.IsOrderPlaced) { user.CardsCount--; //27-feb-2018 } } else { return(new ActionOutput <PostCardResultModel> { Status = ActionStatus.Error, Message = "Your pending tokens are less than the recipient you added. Please add tokens for new orders." }); } } } if (model.SelectedImages != null) { if (model.SelectedImages.Count > 0) { foreach (var item in model.SelectedImages) { var postCardImage = new UserPostCardImage(); postCardImage = Mapper.Map <PostCardSelectedImages, UserPostCardImage>(item, postCardImage); postCardImage.UsedOn = DateTime.UtcNow; postCardImage.UsedBy = model.UserID; book.UserPostCardImages.Add(postCardImage); } } } book.UserOrder = new UserOrder(); book.UserOrder.OrderStatus = (short)eOrderStatus.OrderPlaced; // user.CardsCount--; Context.UserPostCards.Add(book); Context.SaveChanges(); message = "Postcard details added successfully."; id = book.ID; resultObject = new PostCardResultModel(book); } if (user.OrderPlacedNotification == true && user.OrderPlacedNotification != null) { if (model.IsOrderPlaced == true) { IEmailManager _emailManager = new EmailManager(); _emailManager.SendOrderPlacedForUser(user); } } return(new ActionOutput <PostCardResultModel> { Object = resultObject, Status = ActionStatus.Successfull, Message = message }); } catch (Exception ex) { IErrorLogManager er = new ErrorLogManager(); er.LogExceptionToDatabase(ex); return(new ActionOutput <PostCardResultModel> { Status = ActionStatus.Error, Message = ex.Message }); } } else { return(new ActionOutput <PostCardResultModel> { Status = ActionStatus.Error, Message = "You have used all your cards. Please purchase a new plan for more cards." }); } }