Beispiel #1
0
    protected void AddNewSubPurchase(object sender, EventArgs e)
    {
        string[] subpurchasePhoneNumbers = inputSubPurchPhone.Value.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
        string   subpurchaseName         = inputSubPurchName.Value;

        if (!subpurchasePhoneNumbers.Any())
        {
            throw new Exception("Добавьте номер посредника, который хотите разместить в базе.");
        }

        var context = new DataModel();
        var subpurchasesWorkflow = new SubpurchasesWorkflow();

        foreach (var subpurchasePhoneNumber in subpurchasePhoneNumbers)
        {
            if (!string.IsNullOrEmpty(subpurchasePhoneNumber))
            {
                subpurchasesWorkflow.AddSubpurchasePhone(subpurchasePhoneNumber, subpurchaseName, string.Empty, true);

                //--- remove Advertisments with current SubPurchase
                var subPurchaseAdvertisments = from advertisment in context.Advertisments
                                               where advertisment.AdvertismentPhones.Any(advPhone => advPhone.phone == subpurchasePhoneNumber)
                                               select advertisment;
                if (subPurchaseAdvertisments.Count() > 0)
                {
                    foreach (var adv in subPurchaseAdvertisments)
                    {
                        context.Advertisments.DeleteOnSubmit(adv);
                    }
                    context.SubmitChanges();
                }
            }
            Response.Redirect(Request.RawUrl + "?success=1");
        }
    }
Beispiel #2
0
    public bool MarkAsSubpurchase(List <string> phonesList)
    {
        try
        {
            var subpurchasesWorkflow = new SubpurchasesWorkflow();
            foreach (var phone in phonesList)
            {
                subpurchasesWorkflow.AddSubpurchasePhone(phone, false);
            }
        }
        catch
        {
            return(false);
        }

        return(true);
    }