Example #1
0
        public ActionResult Friend(/*Models.Gifts.GiftToFriendModel model*/ FormCollection form)
        {
            Logger.Info("Preparing gift coupon for friend...");
            var model = new GiftToFriendModel();

            TryUpdateModel <GiftToFriendModel>(model, "friendEmail");
            Logger.DebugFormat("  friend e-mail:   `{0}`", model.FriendEmail);
            Logger.DebugFormat("  text for friend: `{0}`", model.Text);

            try
            {
                Factory.GiftsBll.MakeCouponGift(model.ProductUid, model.FriendEmail, model.Text);
            }
            catch (InvalidProductException ipex)
            {
                string msg;
                switch (ipex.Reason)
                {
                case InvalidProductException.Reasons.ProductExpired:
                    msg = ipex.Message;
                    break;

                case InvalidProductException.Reasons.ProductIsGiftAlready:
                    msg = "This coupon was dedicated to other user";
                    break;

                default:
                    msg = Resources.Language.SystemMessage_WeWillContactYouOnError;
                    break;
                }
                this.SetTempMessage(msg);
                return(Error());
            }

            return(OutputFile(model.ProductUid, true, true));
        }
Example #2
0
        // POST: /Gift/EmailFriend
        public ActionResult EmailFriend(FormCollection form)
        {
            bool   isOk = false;
            string msg  = "";

            string[] errors = new string[0];

            Logger.Info("Preparing gift coupon for friend...");
            var model = new GiftToFriendModel();

            TryUpdateModel <GiftToFriendModel>(model, "friendEmail");
            Logger.DebugFormat("  friend e-mail:   `{0}`", model.FriendEmail);
            Logger.DebugFormat("  text for friend: `{0}`", model.Text);

            try
            {
                Factory.GiftsBll.MakeCouponGift(model.ProductUid, model.FriendEmail, model.Text);

                var pdf     = Factory.PdfBll.GeneratProductPdf(model.ProductUid, true);
                var product = Factory.GiftsBll.GetProductInformationByUid(model.ProductUid);
                Factory.CommunicationBll.SendCouponAsGift(model.FriendEmail, pdf, product);

                isOk = true;
                msg  = String.Concat("PDF coupon is successfully sent to your friend email ", model.FriendEmail);
            }
            catch (ValidationListException vex)
            {
                msg = Resources.Language.Gift_EmailFriend_IncorrectParameters;
                if (vex.Errors != null)
                {
                    errors = vex.Errors.Select(x => x.ErrMessage).ToArray();
                }
            }
            catch (InvalidProductException ipex)
            {
                switch (ipex.Reason)
                {
                case InvalidProductException.Reasons.ProductExpired:
                    msg = ipex.Message;
                    break;

                case InvalidProductException.Reasons.ProductIsGiftAlready:
                    msg = "This coupon was dedicated to other user";
                    break;

                default:
                    msg = Resources.Language.SystemMessage_WeWillContactYouOnError;
                    break;
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Error making gift coupon for user", ex);
                msg = "Error sending e-mail";
            }

            return(Json(new
            {
                Status = isOk,
                Message = msg,
                Errors = errors
            }));
        }