/// <summary> /// Get all orders /// </summary> /// <returns></returns> public List<SIOrder> GetOrders(eOrderStatus Status = eOrderStatus.any, eFulfillmentStatus FulfillmentStatus = eFulfillmentStatus.any, eOrderFinancialStatus FinancialStatus = eOrderFinancialStatus.any, int Page = 1) { List<SIOrder> allOrders = new List<SIOrder>(); _endPointURI = "admin/orders.json"; RestClient c = new RestClient(_baseAddress); c.Authenticator = new HttpBasicAuthenticator(_apikey, _password); RestRequest req = new RestRequest(_endPointURI); req.AddParameter("limit", 250); if (Page != 1) req.AddParameter("page", Page); if (Status != eOrderStatus.any) req.AddQueryParameter("status", Status.ToString()); if (FulfillmentStatus != eFulfillmentStatus.any) req.AddQueryParameter("fulfillment_status", FulfillmentStatus.ToString()); if (FinancialStatus != eOrderFinancialStatus.any) req.AddQueryParameter("financial_status", FinancialStatus.ToString()); IRestResponse response = c.Execute(req); RawData += response.Content; if (response.StatusCode != HttpStatusCode.OK) { SetHTTPErrMsg(response); } else { JsonObject json = (JsonObject)SimpleJson.DeserializeObject(response.Content); JsonArray orders = (JsonArray)json["orders"]; //allOrders = SimpleJson.DeserializeObject<List<SIOrder>>(orders.ToString()); foreach (JsonObject jo in orders) { SIOrder o = SimpleJson.DeserializeObject<SIOrder>(jo.ToString()); allOrders.Add(o); } } return allOrders; }
ActionOutput <AddUpdateImageEditorModel> IEditorManager.GetPostCardDetailsByID(int PostCardID = 0, int userID = 0) { var result = new ActionOutput <AddUpdateImageEditorModel>(); if (PostCardID > 0) { var postcard = Context.UserPostCards.FirstOrDefault(x => x.ID == PostCardID); if (postcard != null) { if (userID > 0 && postcard.UserID != userID) { return new ActionOutput <AddUpdateImageEditorModel>() { Message = "No acess for this record.", Status = ActionStatus.Error } } ; var model = new AddUpdateImageEditorModel(); model = Mapper.Map <UserPostCard, AddUpdateImageEditorModel>(postcard, model); model.Recipients = Mapper.Map <List <UserPostCardRecipient>, List <UserRecipientModel> >(postcard.UserPostCardRecipients.ToList(), model.Recipients.ToList()); result.Object = model; result.Message = "Post card details"; result.Status = ActionStatus.Successfull; } else { result.Message = "No Record found."; result.Status = ActionStatus.Error; } } return(result); } ActionOutput <AddUpdateImageEditorModel> IEditorManager.GetDemoPostCardListing() { var emailId = Config.DemoPostCardEmail; var result = new ActionOutput <AddUpdateImageEditorModel>(); if (!string.IsNullOrEmpty(emailId)) { var postcard = Context.UserPostCards.Where(x => x.IsDeleted != true && x.User.Email == emailId).OrderByDescending(x => x.ID).Take(8).ToList(); if (postcard.Count > 0) { var model = new List <AddUpdateImageEditorModel>(); model = Mapper.Map <List <UserPostCard>, List <AddUpdateImageEditorModel> >(postcard.ToList(), model); result.List = model.ToList(); } result.Message = string.Empty; result.Status = ActionStatus.Successfull; } return(result); } ActionOutput IEditorManager.DeletePostCardByID(int PostCardID, int userID = 0) { var postcard = Context.UserPostCards.FirstOrDefault(c => c.ID == PostCardID); if (userID > 0 && postcard.UserID != userID) { return new ActionOutput() { Message = "No access for this postcard.", Status = ActionStatus.Error } } ; postcard.IsDeleted = true; postcard.DeletedOn = DateTime.UtcNow; Context.SaveChanges(); return(new ActionOutput() { Message = "Post card deleted successfully", Status = ActionStatus.Successfull }); } ActionOutput IEditorManager.RejectWithReason(RejectWithReasonModel model) { var postcard = Context.UserPostCardRecipients.FirstOrDefault(c => c.ID == model.RecipientCardID); var msg = ""; if (postcard.IsRejected == true) { postcard.CardStatus = PreviousCardStatus(ref postcard); postcard.IsRejected = false; } else { postcard.IsRejected = true; postcard.IsApproved = false; postcard.IsCompleted = false; postcard.IsError = false; postcard.RejectedOn = DateTime.UtcNow; postcard.RejectedReason = model.Reason; postcard.CardStatus = (int)CardStatusTypes.Rejected; msg = "Rejected successfully"; IEmailManager _em = new EmailManager(); if (postcard.UserPostCard.User.OrderStatusNotification != null && postcard.UserPostCard.User.OrderStatusNotification == true) { _em.SendRejectionEmailToUser(postcard.ID, model.Reason); } postcard.UserHistories.Add(new UserHistory() { UserFK = postcard.UserPostCard.UserID, Type = "Order Rejected", TokenChange = "+1", AddedOn = DateTime.UtcNow, TokenAvailable = postcard.UserPostCard.User.CardsCount }); if (postcard.IsError == false || postcard.IsError == null) { postcard.UserPostCard.User.CardsCount += 1; } } Context.SaveChanges(); return(new ActionOutput() { Message = msg, Status = ActionStatus.Successfull }); } ActionOutput IEditorManager.ApprovePostCardByID(int PostCardID) { IEmailManager _emailManager = new EmailManager(); var status = ""; var message = ""; var postcard = Context.UserPostCards.FirstOrDefault(c => c.ID == PostCardID); if (postcard.IsApproved == true) { postcard.IsApproved = false; postcard.ApprovedOn = null; status = "disapproved"; message = "Post card disapproved successfully"; } else { postcard.IsApproved = true; postcard.ApprovedOn = DateTime.UtcNow; status = "approved"; message = "Post card approved successfully"; } Context.SaveChanges(); if (postcard.User.OrderPlacedNotification == true && postcard.User.OrderPlacedNotification != null) { _emailManager.SendOrderStatusChangeMailForUser(postcard.User, status); } return(new ActionOutput() { Message = message, Status = ActionStatus.Successfull }); } ActionOutput IEditorManager.RejectPostCardByID(int PostCardID) { IEmailManager _emailManager = new EmailManager(); var status = ""; var message = ""; var postcard = Context.UserPostCards.FirstOrDefault(c => c.ID == PostCardID); if (postcard.IsRejected == true) { postcard.IsRejected = false; postcard.RejectedOn = null; message = "Rejection removed successfully"; } else { postcard.IsRejected = true; postcard.RejectedOn = DateTime.UtcNow; message = "Post card rejected successfully"; status = "Rejected"; } if (postcard.User.OrderPlacedNotification == true && postcard.User.OrderPlacedNotification != null) { _emailManager.SendOrderStatusChangeMailForUser(postcard.User, status); } Context.SaveChanges(); return(new ActionOutput() { Message = message, Status = ActionStatus.Successfull }); } ActionOutput IEditorManager.UpdateOrderStatus(int orderID, short Status) { IEmailManager _emailManager = new EmailManager(); eOrderStatus status = (eOrderStatus)Status; var result = new ActionOutput(); var order = Context.UserOrders.FirstOrDefault(c => c.ID == orderID); if (order != null) { order.OrderStatus = Status; Context.SaveChanges(); result.Message = "Order status updated successfully"; result.Status = ActionStatus.Successfull; } else { result.Message = "No record found"; result.Status = ActionStatus.Error; } if (order.UserPostCard.User.OrderPlacedNotification == true && order.UserPostCard.User.OrderPlacedNotification != null) { _emailManager.SendOrderStatusChangeMailForUser(order.UserPostCard.User, status.ToString()); } return(result); } ActionOutput IEditorManager.CancelPostCardByID(int PostCardID) { IEmailManager _emailManager = new EmailManager(); ActionOutput result = new ActionOutput(); result.Message = "Post card request cancelled successfully"; var postcard = Context.UserPostCards.FirstOrDefault(c => c.ID == PostCardID); if (postcard != null) { if (postcard.IsApproved == true) { result.Message = "Card already approved by the admin."; result.Status = ActionStatus.Failed; } if (postcard.IsCancel == true) { result.Message = "Card already cancelled by you."; result.Status = ActionStatus.Failed; } if (postcard.IsCompleted == true) { result.Message = "Card already completed by the admin."; result.Status = ActionStatus.Failed; } if (postcard.IsDeleted == true) { result.Message = "You can not cancel the deleted card."; result.Status = ActionStatus.Failed; } if (postcard.IsRejected == true) { result.Message = "Card already rejected by the admin."; result.Status = ActionStatus.Failed; } if (postcard.AddedOn.Value.AddMinutes(15) >= DateTime.UtcNow) { postcard.IsCancel = true; postcard.CancelledOn = DateTime.UtcNow; foreach (var item in postcard.UserPostCardRecipients) { item.IsCancelled = true; item.CancelledOn = DateTime.UtcNow; item.CardStatus = (int)CardStatusTypes.Cancelled; postcard.User.CardsCount += 1; } Context.SaveChanges(); //if (postcard.User.OrderPlacedNotification == true && postcard.User.OrderPlacedNotification != null) // _emailManager.SendOrderStatusChangeMailForUser(postcard.User, "Cancelled"); _emailManager.SendOrderStatusToAdmin("Cancelled", postcard.User); result.Status = ActionStatus.Successfull; } else { result.Message = "Time expired and now your order is placed."; result.Status = ActionStatus.Failed; } } else { result.Message = "No record found."; result.Status = ActionStatus.Failed; } return(result); } ActionOutput IEditorManager.ApproveReceiptent(int ReceiptentID) { IEmailManager _emailManager = new EmailManager(); var message = ""; var postcard = Context.UserPostCardRecipients.FirstOrDefault(c => c.ID == ReceiptentID); if (postcard.IsApproved == false || postcard.IsApproved == null) { postcard.IsApproved = true; postcard.IsCompleted = false; postcard.IsError = false; postcard.IsRejected = false; postcard.CardStatus = (int)CardStatusTypes.Approved; message = "Post card recipient approved successfully"; //if (postcard.UserPostCard.User.OrderPlacedNotification == true && postcard.UserPostCard.User.OrderPlacedNotification != null) // _emailManager.SendOrderStatusChangeMailForUser(postcard.UserPostCard.User, "recipient approved"); postcard.UserHistories.Add(new UserHistory() { UserFK = postcard.UserPostCard.UserID, Type = "Order", Status = "Order Approved", TokenChange = "", AddedOn = DateTime.UtcNow, TokenAvailable = postcard.UserPostCard.User.CardsCount }); } else { if (postcard.IsApproved == true) { postcard.CardStatus = PreviousCardStatus(ref postcard); postcard.IsApproved = false; postcard.IsError = false; postcard.IsRejected = false; message = "Post card recipients disapproved successfully"; } //if (postcard.UserPostCard.User.OrderPlacedNotification == true && postcard.UserPostCard.User.OrderPlacedNotification != null) // _emailManager.SendOrderStatusChangeMailForUser(postcard.UserPostCard.User, "recipient disapproved"); } Context.SaveChanges(); return(new ActionOutput() { Message = message, Status = ActionStatus.Successfull }); } ActionOutput IEditorManager.CompletePostCard(int postcardID) { IEmailManager _emailManager = new EmailManager(); var message = ""; ActionStatus status; var postcard = Context.UserPostCards.FirstOrDefault(c => c.ID == postcardID); if (postcard != null) { postcard.IsCompleted = true; postcard.CompletedOn = DateTime.UtcNow; message = "Post card completed successfully"; status = ActionStatus.Successfull; Context.SaveChanges(); if (postcard.User.OrderStatusNotification == true && postcard.User.OrderStatusNotification != null) { _emailManager.SendOrderStatusChangeMailForUser(postcard.User, "completed"); } } else { message = "No record found."; status = ActionStatus.Error; } return(new ActionOutput() { Message = message, Status = status }); } ActionOutput IEditorManager.CompleteRecipientPostCard(int ReceiptentID) { IEmailManager _emailManager = new EmailManager(); var message = ""; ActionStatus status; var postcard = Context.UserPostCardRecipients.FirstOrDefault(c => c.ID == ReceiptentID); if (postcard != null) { postcard.IsCompleted = true; postcard.IsApproved = true; postcard.IsRejected = false; postcard.IsError = false; postcard.ApprovedOn = DateTime.UtcNow; postcard.CompletedOn = DateTime.UtcNow; postcard.CardStatus = (int)CardStatusTypes.Completed; message = "Post card completed successfully"; status = ActionStatus.Successfull; Context.SaveChanges(); if (postcard.UserPostCard.User.OrderStatusNotification == true && postcard.UserPostCard.User.OrderStatusNotification != null) { _emailManager.SendCardWasMailedEmail(postcard.UserPostCard.User); _emailManager.SendOrderStatusChangeMailForUser(postcard.UserPostCard.User, "completed"); } postcard.UserHistories.Add(new UserHistory() { UserFK = postcard.UserPostCard.UserID, Type = "Order", Status = "Order Completed", TokenChange = "", AddedOn = DateTime.UtcNow, TokenAvailable = postcard.UserPostCard.User.CardsCount }); } else { message = "No record found."; status = ActionStatus.Error; } return(new ActionOutput() { Message = message, Status = status }); } ActionOutput IEditorManager.DispproveReceiptent(int ReceiptentID) { var message = ""; var postcard = Context.UserPostCardRecipients.FirstOrDefault(c => c.ID == ReceiptentID); if (postcard.IsApproved == true) { postcard.CardStatus = PreviousCardStatus(ref postcard); postcard.IsApproved = false; postcard.IsRejected = false; postcard.IsError = false; message = "Post card recipient disapproved successfully"; Context.SaveChanges(); } else { message = "Post card recipients is already in disapproved state"; } return(new ActionOutput() { Message = message, Status = ActionStatus.Successfull }); } ActionOutput IEditorManager.SentToError(int ReceiptentID) { var message = ""; var postcard = Context.UserPostCardRecipients.FirstOrDefault(c => c.ID == ReceiptentID); if (postcard.IsError == true) { postcard.CardStatus = PreviousCardStatus(ref postcard); postcard.IsError = false; postcard.IsRejected = false; message = "remove from errors successfully"; if (postcard.IsRejected == false || postcard.IsRejected == null) { postcard.UserPostCard.User.CardsCount -= 1; } } else { postcard.IsError = true; postcard.IsRejected = false; postcard.CardStatus = (int)CardStatusTypes.Error; message = "Sent to errors successfully"; if (postcard.IsRejected == false || postcard.IsRejected == null) { postcard.UserPostCard.User.CardsCount += 1; } } Context.SaveChanges(); return(new ActionOutput() { Message = message, Status = ActionStatus.Successfull }); } ActionOutput IEditorManager.GetPostCardBackSideJsonResult(int ReceiptentID) { List <string> result = new List <string>(); var message = ""; var postcard = Context.UserPostCardRecipients.FirstOrDefault(c => c.ID == ReceiptentID); if (postcard != null) { if (postcard.UserPostCard.CardBackJsonWithIFrame != null) { result.Add(postcard.UserPostCard.CardBackJsonWithIFrame); } else { result.Add(postcard.UserPostCard.CardBackJson); } message = "remove from errors successfully"; } else { postcard.IsError = true; message = "Sent to errors successfully"; } return(new ActionOutput() { Message = message, Results = result, Status = ActionStatus.Successfull }); }
public int GetOrderCount(eOrderStatus Status = eOrderStatus.any, eFulfillmentStatus FulfillmentStatus = eFulfillmentStatus.any, eOrderFinancialStatus FinancialStatus = eOrderFinancialStatus.any) { int count = 0; _endPointURI = "admin/orders/count.json"; RestClient c = new RestClient(_baseAddress); c.Authenticator = new HttpBasicAuthenticator(_apikey, _password); RestRequest req = new RestRequest(_endPointURI); if (Status != eOrderStatus.any) req.AddQueryParameter("status", Status.ToString()); if (FulfillmentStatus != eFulfillmentStatus.any) req.AddQueryParameter("fulfillment_status", FulfillmentStatus.ToString()); if (FinancialStatus != eOrderFinancialStatus.any) req.AddQueryParameter("financial_status", FinancialStatus.ToString()); IRestResponse response = c.Execute(req); RawData += response.Content; if (response.StatusCode != HttpStatusCode.OK) { SetHTTPErrMsg(response); } else { JsonObject json = (JsonObject)SimpleJson.DeserializeObject(response.Content); count = Convert.ToInt32(json["count"]); } return count; }