Exemple #1
0
        private void fixall(GlobalComment gc)
        {
            if (gc.Comment.IsNullOrWhiteSpace())
            {
                return;
            }

            gc.UserId.IsNullOrWhiteSpaceThrowException("User is not logged in");

            if (!gc.UserId.IsNullOrWhiteSpace())
            {
                ApplicationUser user = _userBiz.Find(gc.UserId);
                user.IsNullThrowException();
                //user.GlobalComments.Add(gc);
                gc.Name = UserName;
            }



            if (!gc.MenuPath1Id.IsNullOrWhiteSpace())
            {
                MenuPath1 m1 = _menuPathMainBiz.MenuPath1Biz.Find(gc.MenuPath1Id);
                m1.IsNullThrowException();
                m1.GlobalComments.Add(gc);
                return;
            }


            if (!gc.MenuPath2Id.IsNullOrWhiteSpace())
            {
                MenuPath2 m2 = _menuPathMainBiz.MenuPath2Biz.Find(gc.MenuPath2Id);
                m2.IsNullThrowException();
                m2.GlobalComments.Add(gc);
                return;
            }


            if (!gc.MenuPath3Id.IsNullOrWhiteSpace())
            {
                MenuPath3 m3 = _menuPathMainBiz.MenuPath3Biz.Find(gc.MenuPath3Id);
                m3.IsNullThrowException();
                m3.GlobalComments.Add(gc);
            }


            if (!gc.ProductId.IsNullOrWhiteSpace())
            {
                Product p = _productBiz.Find(gc.ProductId);
                p.IsNullThrowException();
                p.GlobalComments.Add(gc);
            }


            if (!gc.ProductChildId.IsNullOrWhiteSpace())
            {
                ProductChild pc = _productBiz.ProductChildBiz.Find(gc.ProductChildId);
                pc.IsNullThrowException();
                pc.GlobalComments.Add(gc);
            }
        }
Exemple #2
0
        private void getPicture(ProductChildInitializer item, ProductChild pc)
        {
            IHasUploads pcHasuploads = pc as IHasUploads;

            pc.IsNullThrowException(string.Format("Programming Error. Product Child is not showing as IHasUploads. It is. Currently initializing '{0}'", item.ProductName));

            string originalname        = item.ProductName.RemoveAllSpaces().ToString();
            string relative_SrcPath    = pc.MiscFilesLocation_Initialization();
            string relative_targetPath = pc.MiscFilesLocation(UserName);

            string filenameNoExtention = getFileNameWithoutExtention(relative_SrcPath, originalname);


            if (!imageFileExists(filenameNoExtention))
            {
                return;
            }

            #region Copy File
            string originalnameWithoutExtention = originalname;
            List <UploadedFile> uploadedFileLst = new List <UploadedFile>();

            //copy the actual file to the new spot. We need to do it here so we can get it's new name
            //== COPY FILE
            string newNameWithMappedPathPlusExtention = CopyFile(relative_SrcPath, relative_targetPath, Path.ChangeExtension(originalnameWithoutExtention, ExtentionFound));

            //create the upload file
            UploadedFile uf = new UploadedFile(
                originalnameWithoutExtention,
                Path.GetFileNameWithoutExtension(newNameWithMappedPathPlusExtention),
                ExtentionFound,
                relative_targetPath);

            //add to uploadlist
            uploadedFileLst.Add(uf);

            #endregion
            if (!uploadedFileLst.IsNullOrEmpty())
            {
                foreach (UploadedFile file in uploadedFileLst)
                {
                    file.MetaData.Created.SetToTodaysDate(UserName, UserId);


                    //initializes navigation if it is null

                    //You need to add a refrence here to save the file in the UploadedFile as well.
                    file.ProductChild   = pc;
                    file.ProductChildId = pc.Id;

                    if (pcHasuploads.MiscFiles.IsNull())
                    {
                        pcHasuploads.MiscFiles = new List <UploadedFile>(); //intializing
                    }
                    pcHasuploads.MiscFiles.Add(file);

                    UploadedFileBiz.Create(CreateControllerCreateEditParameter(file as ICommonWithId));
                }
            }
        }
        //this recieves a list of selected product children Ids from MessageParameter and then gets the
        //product children and returns them
        private List <ProductChild> getProductChildrenFromCheckItem(MessageParameter msgParam)
        {
            List <ProductChild> selectedList = new List <ProductChild>();

            if (!msgParam.GetProductChildrenAddyFromCheckItems().IsNullOrEmpty())
            {
                foreach (string pChildAddy in msgParam.GetProductChildrenAddyFromCheckItems())
                {
                    ProductChild productChild = ProductChildBiz.Find(pChildAddy);
                    productChild.IsNullThrowException("productChild");
                    selectedList.Add(productChild);
                }
            }

            return(selectedList);
        }
Exemple #4
0
        private void addNewAddress(ICommonWithId entity, Person person, AddressBiz addressBiz, AddressMain addressToSave)
        {
            ProductChild pc = entity as ProductChild;

            pc.IsNullThrowException();

            pc.ShipFromAddressId = addressToSave.Id;

            if (addressToSave.ProductChilds.IsNull())
            {
                addressToSave.ProductChilds = new List <ProductChild>();
            }

            addressToSave.ProductChilds.Add(pc);

            person.Addresses.Add(addressToSave);
            addressToSave.PersonId = person.Id;
            addressBiz.Create(addressToSave);
        }
Exemple #5
0
        /// <summary>
        /// Every Owner can add only One product of a specific name.
        /// We need to load the product in this at a higher level because we are unable to access ProductBiz here
        /// </summary>
        /// <param name="parm"></param>
        public override void Fix(ControllerCreateEditParameter parm)
        {
            UserId.IsNullOrWhiteSpaceThrowException("You are not logged in.");

            ProductChild pc = parm.Entity as ProductChild;

            pc.IsNullThrowException("Unable to unbox Product Child");

            //Product comes from the controller.
            pc.ProductId.IsNullOrWhiteSpaceThrowException("There is no parent Product");
            pc.Product.IsNullThrowException("Product Has not been loaded!");


            if (pc.Name.IsNullOrWhiteSpace())
            {
                pc.Name = pc.Product.Name;
            }

            //we need to load the owner in because the name is used to create
            //a directory for the uploads.
            //first get the Owners Id
            Owner owner = OwnerBiz.GetOwnerForUser(UserId);

            owner.IsNullThrowException("Owner not found!");
            pc.OwnerId = owner.Id;
            pc.Owner   = owner;

            ////I dont want to add the features. I will add them temporarily when it is being presented,
            ////addProductFeatures(pc);
            FixProductChildFeatures(pc);

            base.Fix(parm);

            //check the address. If the address is a new address, make it past of the database for the ProductChild Owner
            //check if the address exists

            AddShippingAddressToOwnerPersonIfItIsNew(pc);
            //AddPhoneNumberToOwnerPersonIfItsNew(pc);
        }
        //This supplies a dummy MenuPathMain for the Back to List in the Create.
        protected IMenuManager makeMenuManager(ControllerIndexParams parm)
        {
            MenuPathMain mpm = null;
            Product      p   = null;
            ProductChild pc  = null;

            switch (parm.MenuEnum)
            {
            case EnumLibrary.EnumNS.MenuENUM.IndexMenuPath2:
            case EnumLibrary.EnumNS.MenuENUM.IndexMenuPath3:
            case EnumLibrary.EnumNS.MenuENUM.IndexMenuProduct:

                parm.MenuPathMainId.IsNullOrWhiteSpaceThrowException();
                string mpmId = parm.MenuPathMainId;
                mpm = Find(mpmId);
                mpm.IsNullThrowException();
                break;

            case EnumLibrary.EnumNS.MenuENUM.IndexMenuProductChild:

                parm.ProductId.IsNullOrWhiteSpaceThrowException();
                string pId = parm.ProductId;
                p = ProductBiz.Find(pId);
                p.IsNullThrowException();
                break;

            case EnumLibrary.EnumNS.MenuENUM.IndexMenuProductChildLandingPage:

                parm.ProductChildId.IsNullOrWhiteSpaceThrowException();
                string productChildId = parm.ProductChildId;
                pc = ProductChildBiz.Find(productChildId);
                pc.IsNullThrowException();

                //add the features
                pc.AllFeatures = ProductChildBiz.Get_All_ProductChild_Features_For(pc);
                break;

            case EnumLibrary.EnumNS.MenuENUM.IndexMenuPath1:
            case EnumLibrary.EnumNS.MenuENUM.EditMenuPath1:
            case EnumLibrary.EnumNS.MenuENUM.EditMenuPath2:
            case EnumLibrary.EnumNS.MenuENUM.EditMenuPath3:
            case EnumLibrary.EnumNS.MenuENUM.EditMenuPathMain:
            case EnumLibrary.EnumNS.MenuENUM.EditMenuProduct:
            case EnumLibrary.EnumNS.MenuENUM.EditMenuProductChild:
            case EnumLibrary.EnumNS.MenuENUM.CreateMenuPath1:
            case EnumLibrary.EnumNS.MenuENUM.CreateMenuPath2:
            case EnumLibrary.EnumNS.MenuENUM.CreateMenuPath3:
            case EnumLibrary.EnumNS.MenuENUM.CreateMenuPathMenuPathMain:
            case EnumLibrary.EnumNS.MenuENUM.CreateMenuProduct:
            case EnumLibrary.EnumNS.MenuENUM.CreateMenuProductChild:
            default:
                break;
            }

            MenuManager mm = new MenuManager(mpm, p, pc, parm.MenuEnum, parm.BreadCrumbManager, parm.LikeUnlikeCounter, UserId, parm.ReturnUrl, UserName);

            mm.BreadCrumbManager = parm.BreadCrumbManager;
            //mm.IndexMenuVariables.IsAdmin = UserBiz.IsAdmin(UserId);


            if (!UserId.IsNullOrWhiteSpace())
            {
                Person person = CashTrxBiz.PersonBiz.GetPersonForUserId(UserId);
                if (person.IsNull())
                {
                    //mm.UserMoneyAccount = new UserMoneyAccount();
                }
                else
                {
                    bool isBank = BankBiz.IsBanker_User(UserId);
                    //swithched off to get rid of error. MAY NEED IT BACK!
                    //mm.UserMoneyAccount = MoneyAccountForPerson(person.Id, isBank);
                }
            }


            return(mm as IMenuManager);
        }
Exemple #7
0
        /// <summary>
        /// This is being used for Pickups.
        /// </summary>
        /// <param name="indexListVM"></param>
        /// <param name="indexItemVM"></param>
        /// <param name="icommonWithId"></param>
        public override void Event_ModifyIndexItem(IndexListVM indexListVM, IndexItemVM indexItemVM, ICommonWithId icommonWithId)
        {
            base.Event_ModifyIndexItem(indexListVM, indexItemVM, icommonWithId);

            //conversions
            BuySellItem buySellItem = icommonWithId as BuySellItem;

            buySellItem.IsNullThrowException();
            buySellItem.ProductChild.IsNullThrowException();

            ProductChild productChild = buySellItem.ProductChild;

            productChild.IsNullThrowException();
            indexItemVM.Description = productChild.DetailInfoToDisplayOnWebsite;


            BuySellDoc buySellDoc = buySellItem.BuySellDoc;

            buySellDoc.IsNullThrowException();

            UploadedFile uf = productChild.MiscFiles.FirstOrDefault(x => !x.MetaData.IsDeleted);

            //product child has no image?
            if (uf.IsNull())
            {
                uf = productChild.Product.MiscFiles.FirstOrDefault(x => !x.MetaData.IsDeleted);
            }

            indexItemVM.MenuManager = new MenuManager(null, null, productChild, MenuENUM.IndexMenuProductChild, BreadCrumbManager, new LikeUnlikeParameters(0, 0, ""), UserId, indexListVM.MenuManager.ReturnUrl, UserName);

            //get the pictures list from the productChild
            List <string> pictureAddresses = GetCurrItemsPictureList(productChild);

            //if none are available get them from the product
            if (pictureAddresses.IsNullOrEmpty())
            {
                productChild.Product.IsNullThrowException();
                pictureAddresses = GetCurrItemsPictureList(productChild.Product);
            }

            indexItemVM.MenuManager.PictureAddresses = pictureAddresses;
            //indexItem.PictureViews = productChild.NoOfVisits.Amount;
            //indexItem.CompleteMenuPathViews = productChild.NoOfVisits.Amount;

            //indexItem.Price = productChild.Sell.SellPrice;

            AddEntryToIndex = buySellItem.BuySellDocStateEnum == BuySellDocStateENUM.ReadyForPickup;

            string countyName = buySellDoc.AddressShipToComplex.CountryName;
            string cityName   = buySellDoc.AddressShipToComplex.CityName;
            string townName   = buySellDoc.AddressShipToComplex.TownName;

            //add the price into the 2nd heading

            if (!countyName.IsNullOrWhiteSpace() && !cityName.IsNullOrWhiteSpace() && !townName.IsNullOrWhiteSpace())
            {
                indexItemVM.Amount2ndLine = string.Format("{0} {1}, {2}", townName, cityName, countyName);
            }
            else
            {
                if (!countyName.IsNullOrWhiteSpace() && !cityName.IsNullOrWhiteSpace() && townName.IsNullOrWhiteSpace())
                {
                    indexItemVM.Amount2ndLine = string.Format("{0}, {1}", cityName, countyName);
                }
                else
                {
                    throw new Exception("Address incomplete");
                }
            }

            indexItemVM.IsPickup = true;
            indexItemVM.ParentId = buySellDoc.Id;
            //buySellDoc.BuySellDocumentTypeEnum = BuySellDocumentTypeENUM.Delivery;
        }
        /// <summary>
        /// The Menu will always run the MenuBiz.
        /// We do not care about the MenuManager in the ICommonWithId level. That is used in Create/Edit
        /// We need to load the MenuManager with the correct MainMenuPath so that it can be used in the _IndexMiddlePart - TiledPictures.cshtml
        /// We cant use the one in the list because that is a single one and the one that is used in the itme needs to have the
        /// MenuPath1 id. Moreover, the Id of the IndexItem is MenuPathMainId, so it is of no use.
        /// I want the menu's to be dimmed if they have no products. Moreover, The pictures from products need to bubble up to the top, at least 5...
        /// </summary>
        /// <param name="indexListVM"></param>
        /// <param name="indexItem"></param>
        /// <param name="icommonWithId"></param>
        public override void Event_ModifyIndexItem(IndexListVM indexListVM, IndexItemVM indexItem, ICommonWithId icommonWithId)
        {
            //The icommonWithId is the item that is running in the Forloop in the calling procedure
            //The icommonWithId comes here for the first 3 menus as a MenuPathMain item.
            //Then on the 4th it comes as a product.
            //You must select the correct MenuState Here as well
            base.Event_ModifyIndexItem(indexListVM, indexItem, icommonWithId);
            int returnNoOfPictures = MenuPath1.MaxNumberOfPicturesInMenu() + 1;


            MenuPathMain mpm          = icommonWithId as MenuPathMain;
            ProductChild productChild = icommonWithId as ProductChild;
            Product      product      = icommonWithId as Product;


            LikeUnlikeParameters likeUnlikeCounter;
            //UploadedFile uf;
            List <string> pictureAddresses = new List <string>();
            List <string> currPcs          = new List <string>();

            //List<string> lstOfPictures = new List<string>();
            //string theUserId = indexListVM.UserId ?? "";
            string theUserId = UserId;



            MenuEnumForDefaultPicture = indexListVM.MenuManager.MenuState.MenuEnum;
            switch (indexListVM.MenuManager.MenuState.MenuEnum)
            {
            case MenuENUM.IndexMenuPath1:
                mpm.IsNullThrowException();
                mpm.MenuPath1.IsNullThrowException();

                //get the likes and unlikes for MenuPath1
                likeUnlikeCounter            = LikeUnlikeBiz.Count(mpm.MenuPath1.Id, null, null, null, null, theUserId, false);
                likeUnlikeCounter.KindOfLike = "Event_ModifyIndexItem.MenuENUM.IndexMenuPath1";

                indexItem.MenuManager = new MenuManager(mpm, product, productChild, MenuENUM.IndexMenuPath1, BreadCrumbManager, likeUnlikeCounter, UserId, indexListVM.MenuManager.ReturnUrl, UserName);

                indexItem.PictureViews = mpm.MenuPath1.NoOfVisits.Amount;

                //we need to change the image address to image of MenuPath1

                currPcs          = GetCurrItemsPictureList(mpm.MenuPath1 as IHasUploads);
                pictureAddresses = picturesForMenuPath(mpm.MenuPath1);

                //pictureAddresses = joinCurrPicsAndPictureAddresses(pictureAddresses, currPcs);

                if (!currPcs.IsNullOrEmpty())
                {
                    pictureAddresses = pictureAddresses.Concat(currPcs).ToList();
                }

                indexItem.Name               = mpm.MenuPath1.FullName();
                indexItem.Description        = mpm.MenuPath1.DetailInfoToDisplayOnWebsite;
                indexItem.HasProductsForSale = mpm.HasLiveProductChildren;
                indexItem.NoOfItems          = mpm.NoOfItems;
                indexItem.NoOfShops          = mpm.NoOfShops;
                break;


            case MenuENUM.IndexMenuPath2:
                mpm.IsNullThrowException();
                mpm.MenuPath2.IsNullThrowException();
                indexItem.Description = mpm.MenuPath2.DetailInfoToDisplayOnWebsite;

                //uf = mpm.MenuPath2.MiscFiles.FirstOrDefault(x => !x.MetaData.IsDeleted);
                //getPictureList(indexItem, mpm.MenuPath2);

                //indexItem.ImageAddressStr = getImage(uf);
                indexItem.Name               = mpm.MenuPath2.FullName();
                likeUnlikeCounter            = LikeUnlikeBiz.Count(null, mpm.MenuPath2.Id, null, null, null, theUserId, false);
                likeUnlikeCounter.KindOfLike = "Event_ModifyIndexItem.MenuENUM.IndexMenuPath2";
                indexItem.MenuManager        = new MenuManager(mpm, product, productChild, MenuENUM.IndexMenuPath2, BreadCrumbManager, likeUnlikeCounter, UserId, indexListVM.MenuManager.ReturnUrl, UserName);


                indexItem.CompleteMenuPathViews = getMp2Count(mpm);
                indexItem.PictureViews          = mpm.MenuPath2.NoOfVisits.Amount;

                indexItem.HasProductsForSale = mpm.HasLiveProductChildren;
                indexItem.NoOfItems          = mpm.NoOfItems;
                indexItem.NoOfShops          = mpm.NoOfShops;

                currPcs          = GetCurrItemsPictureList(mpm.MenuPath2 as IHasUploads);
                pictureAddresses = picturesForMenuPath(mpm.MenuPath1, mpm.MenuPath2);

                //pictureAddresses = joinCurrPicsAndPictureAddresses(pictureAddresses, currPcs);


                break;



            case MenuENUM.IndexMenuPath3:
                mpm.IsNullThrowException();
                //mpm.MenuPath3.IsNullThrowException(""); //this means there are no menu 3s. This is not allowed.
                if (mpm.MenuPath3.IsNull())
                {
                    return;
                }


                indexItem.Description = mpm.MenuPath3.DetailInfoToDisplayOnWebsite;
                //uf = mpm.MenuPath3.MiscFiles.FirstOrDefault(x => !x.MetaData.IsDeleted);

                //indexItem.ImageAddressStr = getImage(uf);
                //getPictureList(indexItem, mpm.MenuPath3);

                indexItem.Name    = mpm.MenuPath3.FullName();
                likeUnlikeCounter = LikeUnlikeBiz.Count(null, null, mpm.MenuPath3.Id, null, null, theUserId, false);

                likeUnlikeCounter.KindOfLike = "Event_ModifyIndexItem.MenuENUM.IndexMenuPath3";
                indexItem.MenuManager        = new MenuManager(mpm, product, productChild, MenuENUM.IndexMenuPath3, BreadCrumbManager, likeUnlikeCounter, UserId, indexListVM.MenuManager.ReturnUrl, UserName);

                indexItem.PictureViews          = mpm.MenuPath3.NoOfVisits.Amount;
                indexItem.CompleteMenuPathViews = mpm.NoOfVisits.Amount;

                indexItem.HasProductsForSale = mpm.HasLiveProductChildren;

                indexItem.NoOfItems = mpm.NoOfItems;
                indexItem.NoOfShops = mpm.NoOfShops;


                currPcs          = GetCurrItemsPictureList(mpm.MenuPath3 as IHasUploads);
                pictureAddresses = picturesForMenuPath(mpm);
                //pictureAddresses = joinCurrPicsAndPictureAddresses(pictureAddresses, currPcs);


                break;



            case MenuENUM.IndexMenuProduct:     //Products are coming
                product.IsNullThrowException();
                indexItem.Description = product.DetailInfoToDisplayOnWebsite;

                //uf = product.MiscFiles.FirstOrDefault(x => !x.MetaData.IsDeleted);

                likeUnlikeCounter            = LikeUnlikeBiz.Count(null, null, null, product.Id, null, theUserId, false);
                likeUnlikeCounter.KindOfLike = "Event_ModifyIndexItem.MenuENUM.IndexMenuProduct";
                indexItem.MenuManager        = new MenuManager(mpm, product, productChild, MenuENUM.IndexMenuProduct, BreadCrumbManager, likeUnlikeCounter, UserId, indexListVM.MenuManager.ReturnUrl, UserName);

                currPcs = GetCurrItemsPictureList(product as IHasUploads);
                if (product.IsShop)
                {
                    pictureAddresses = getShopPictures(product);
                }
                else
                {
                    pictureAddresses = picturesForProducts(product);
                }


                indexItem.MenuManager.PictureAddresses = pictureAddresses;

                indexItem.PictureViews          = product.NoOfVisits.Amount;
                indexItem.CompleteMenuPathViews = product.NoOfVisits.Amount;

                indexItem.HasProductsForSale = product.HasLiveProductChildren;
                indexItem.NoOfItems          = product.ProductChildren_Fixed_Not_Hidden.Count;

                markUserAsOwnerOfShop(indexItem, product);
                indexItem.IsShop = product.IsShop;
                if (indexItem.IsShopAndOwnerOfShop)
                {
                    indexItem.ShopExpiresStr = ExpiryDateInNoOfDays(product.ShopExpiryDate.Date_NotNull_Max);
                }
                break;


            case MenuENUM.IndexMenuProductChild:
                productChild.IsNullThrowException();
                indexItem.Description            = productChild.DetailInfoToDisplayOnWebsite;
                indexItem.IsTokenPaymentAccepted = productChild.IsNonRefundablePaymentAccepted;
                indexItem.IsHidden = productChild.Hide;

                likeUnlikeCounter            = LikeUnlikeBiz.Count(null, null, null, null, productChild.Id, theUserId, false);
                likeUnlikeCounter.KindOfLike = "Event_ModifyIndexItem.MenuENUM.IndexMenuProductChild";
                indexItem.MenuManager        = new MenuManager(mpm, product, productChild, MenuENUM.IndexMenuProductChild, BreadCrumbManager, likeUnlikeCounter, UserId, indexListVM.MenuManager.ReturnUrl, UserName);

                Person person = UserBiz.GetPersonFor(UserId);
                if (!person.IsNull())
                {
                    string userPersonId         = person.Id;
                    string productChildPersonId = productChild.Owner.PersonId;
                    indexItem.MenuManager.IndexMenuVariables.updateRequiredProperties(userPersonId, productChildPersonId);
                }

                //get the pictures list from the productChild
                currPcs = GetCurrItemsPictureList(productChild);

                ////if none are available get them from the product
                //if (pictureAddresses.IsNullOrEmpty())
                //{
                //    productChild.Product.IsNullThrowException();
                //    pictureAddresses = GetCurrItemsPictureList(productChild.Product);

                //}

                indexItem.PictureViews          = productChild.NoOfVisits.Amount;
                indexItem.CompleteMenuPathViews = productChild.NoOfVisits.Amount;

                indexItem.Price = productChild.Sell.SellPrice;
                break;


            case MenuENUM.EditMenuPath1:
            case MenuENUM.EditMenuPath2:
            case MenuENUM.EditMenuPath3:
            case MenuENUM.EditMenuPathMain:
            case MenuENUM.EditMenuProduct:
            case MenuENUM.EditMenuProductChild:
            case MenuENUM.CreateMenuPath1:
            case MenuENUM.CreateMenuPath2:
            case MenuENUM.CreateMenuPath3:
            case MenuENUM.CreateMenuPathMenuPathMain:
            case MenuENUM.CreateMenuProduct:
            case MenuENUM.CreateMenuProductChild:
            default:
                likeUnlikeCounter            = LikeUnlikeBiz.Count(null, null, null, null, null, theUserId, false);
                likeUnlikeCounter.KindOfLike = "Event_ModifyIndexItem.Default";

                break;
            }



            pictureAddresses = joinCurrPicsAndPictureAddresses(pictureAddresses, currPcs);

            string startSort = getStartSort(indexItem, indexListVM);

            indexItem.Input1SortString = startSort + indexItem.Input1SortString;
            indexItem.Input2SortString = startSort + indexItem.Input2SortString;
            indexItem.Input3SortString = startSort + indexItem.Input3SortString;

            if (pictureAddresses.IsNullOrEmpty())
            {
                pictureAddresses = GetDefaultPicture();
            }

            indexItem.MenuManager.PictureAddresses = pictureAddresses;


            indexItem.MenuManager.LikeUnlikesCounter = likeUnlikeCounter;
            indexItem.MenuManager.BreadCrumbManager  = indexListVM.MenuManager.BreadCrumbManager;

            if (!UserId.IsNullOrWhiteSpace())
            {
                Person person = UserBiz.GetPersonFor(UserId);
                person.IsNullThrowException("person");
                indexItem.MenuManager.UserPersonId = person.Id;
            }
        }
        public string AddToSale(string userId, string productChildId, string poNumber, DateTime poDate)
        {
            userId.IsNullOrWhiteSpaceThrowException("No user");

            double totalThisItem = 0;

            //who is the owner:The product Child owner is the owner
            //get the productChild

            productChildId.IsNullOrWhiteSpaceThrowException("No Product");
            ProductChild productChild = ProductChildBiz.Find(productChildId);

            productChild.IsNullThrowException("productChild");



            //get the product child's owner
            Owner ownerProductChild = productChild.Owner;

            ownerProductChild.IsNullThrowException("productChildOwner");

            //get the owner
            //Get the select list for owner
            Person ownerPerson = ownerProductChild.Person;

            ownerPerson.IsNullThrowException("ownerPerson");
            System.Web.Mvc.SelectList ownerSelectList = OwnerBiz.SelectListOnlyWith(ownerProductChild);


            ////the user is the customer user;
            //get the customer
            Customer customerUser = CustomerBiz.GetPlayerFor(userId);

            //Get the select list for Customer
            //remove the owner from the list... owner cannot sell to self.
            System.Web.Mvc.SelectList customerSelectList = CustomerBiz.SelectListWithout(ownerPerson);
            System.Web.Mvc.SelectList selectListOwner    = OwnerBiz.SelectListOnlyWith(ownerProductChild);
            System.Web.Mvc.SelectList selectListCustomer = CustomerBiz.SelectListWithout(ownerPerson);

            //this is the address in the customer
            AddressMain    addressBillTo          = customerUser.DefaultBillAddress;
            AddressMain    addressShipTo          = customerUser.DefaultShipAddress;
            AddressComplex addressShipFromComplex = productChild.ShipFromAddressComplex;

            string addressBillToId = "";
            string addressShipToId = "";

            if (!addressBillTo.IsNull())
            {
                addressBillToId = addressBillTo.Id;
            }

            if (!addressShipTo.IsNull())
            {
                addressShipToId = addressShipTo.Id;
            }


            //Get the select list for AddressInform
            System.Web.Mvc.SelectList selectListBillTo = AddressBiz.SelectListBillAddressCurrentUser();
            //Get the select list for AddressShipTo
            System.Web.Mvc.SelectList selectListShipTo = AddressBiz.SelectListShipAddressCurrentuser();



            //check to see if there is any open sale which belongs to the same buyer and seller
            BuySellDoc sale = BuySellDocBiz.GetOpenSaleWithSameCustomerAndSeller(customerUser.Id, ownerProductChild.Id, productChild);

            //create the itemList.
            List <BuySellItem> buySellItems = new List <BuySellItem>();
            string             shopId       = "";

            if (sale.IsNull())
            {
                //otherwise add a new sale
                sale = CreateSale(
                    productChild,
                    ownerProductChild,
                    1,
                    productChild.Sell.SellPrice,
                    customerUser,
                    selectListOwner,
                    selectListCustomer,
                    addressBillToId,
                    addressShipToId,
                    selectListBillTo,
                    selectListShipTo,
                    BuySellDocStateENUM.RequestUnconfirmed,
                    BuySellDocStateModifierENUM.Unknown,
                    DateTime.Now,
                    DateTime.Now,
                    shopId);

                totalThisItem++;
            }

            else
            {
                //dont really need this, but it is good for consistancy.
                sale.BuySellDocumentTypeEnum = BuySellDocumentTypeENUM.Purchase;
                sale.BuySellDocStateEnum     = BuySellDocStateENUM.RequestUnconfirmed;

                //now check to see if it is the same item... or is it a new item
                //get list of items for the sale
                List <BuySellItem> itemList = sale.BuySellItems.Where(x => x.MetaData.IsDeleted == false).ToList();

                if (itemList.IsNullOrEmpty())
                {
                    BuySellItem buySellItem = new BuySellItem(sale.Id, productChild.Id, 1, productChild.Sell.SellPrice, productChild.FullName());
                    sale.Add(buySellItem);
                }
                else
                {
                    //there are items in the list
                    BuySellItem itemFound = itemList.FirstOrDefault(x => x.ProductChildId == productChild.Id);
                    if (itemFound.IsNull())
                    {
                        BuySellItem buySellItem = new BuySellItem(sale.Id, productChild.Id, 1, productChild.Sell.SellPrice, productChild.FullName());
                        sale.Add(buySellItem);
                    }
                    else
                    {
                        totalThisItem                     = itemFound.Quantity.Order;
                        itemFound.Quantity.Order         += 1;
                        itemFound.Quantity.Order_Original = itemFound.Quantity.Order;
                        //itemFound.Quantity.Ship += 1;
                    }
                }

                totalThisItem++;
                sale.AddressShipFromComplex = addressShipFromComplex;

                BuySellDocBiz.GetDefaultVehicalType(sale);
                sale.AddressShipFromId = productChild.ShipFromAddressId;

                sale.RequestUnconfirmed.SetToTodaysDate(UserName, UserId);

                ControllerCreateEditParameter parm = new ControllerCreateEditParameter();
                parm.Entity       = sale as ICommonWithId;
                parm.GlobalObject = GetGlobalObject();

                BuySellDocBiz.Update(parm);
            }

            BuySellDocBiz.SaveChanges();
            string message = string.Format("Success. You ordered {0:N2} for {1:N2} (X{2:N2})", productChild.FullName(), productChild.Sell.SellPrice, totalThisItem);

            return(message);
        }
Exemple #10
0
        public bool AddAndSaveComment(GlobalComment gc)
        {
            if (gc.Comment.IsNullOrWhiteSpace())
            {
                return(false);
            }

            gc.UserId.IsNullOrWhiteSpaceThrowException("No user is logged in!");


            if (!gc.MenuPath1Id.IsNullOrWhiteSpace())
            {
                MenuPath1 m1 = _menuPathMainBiz.MenuPath1Biz.Find(gc.MenuPath1Id);
                m1.IsNullThrowException();
                m1.GlobalComments.Add(gc);
            }


            if (!gc.MenuPath2Id.IsNullOrWhiteSpace())
            {
                MenuPath2 m2 = _menuPathMainBiz.MenuPath2Biz.Find(gc.MenuPath2Id);
                m2.IsNullThrowException();
                m2.GlobalComments.Add(gc);
            }


            if (!gc.MenuPath3Id.IsNullOrWhiteSpace())
            {
                MenuPath3 m3 = _menuPathMainBiz.MenuPath3Biz.Find(gc.MenuPath3Id);
                m3.IsNullThrowException();
                m3.GlobalComments.Add(gc);
            }


            if (!gc.ProductId.IsNullOrWhiteSpace())
            {
                Product p = _productBiz.Find(gc.ProductId);
                p.IsNullThrowException();
                p.GlobalComments.Add(gc);
            }


            if (!gc.ProductChildId.IsNullOrWhiteSpace())
            {
                ProductChild pc = _productBiz.ProductChildBiz.Find(gc.ProductChildId);
                pc.IsNullThrowException();
                pc.GlobalComments.Add(gc);
            }

            if (!gc.UserId.IsNullOrWhiteSpace())
            {
                ApplicationUser user = _userBiz.Find(gc.UserId);
                user.IsNullThrowException();
                //user.GlobalComments.Add(gc);
            }

            gc.Name = UserName;

            ControllerCreateEditParameter parm = new ControllerCreateEditParameter();

            parm.Entity = gc as ICommonWithId;

            CreateAndSave(parm);
            return(true);
        }
Exemple #11
0
        private ControllerCreateEditParameter setup_Shop_Into_ControllerCreateEditParameter(
            ShopVM shopCreate,
            string button,
            HttpPostedFileBase[] httpMiscUploadedFiles,
            Owner userOwner,
            out CashDistributionEngine cde,
            out int quantity,
            out Product product,
            out MenuPathMain mpm,
            out ControllerCreateEditParameter parm)
        {
            decimal paymentAmount = MenuPathMain.Payment_To_Buy_Shop();
            decimal commissionPct = BuySellDoc.Get_Maximum_Commission_Product_Percent();
            bool    isNonRefundablePaymentAllowed = true;

            cde = get_CashDistributionEngineAndCheckBalance(paymentAmount, isNonRefundablePaymentAllowed);

            //check the name, if it is already used, throw error and return to create screen
            if (isShopNameExists(shopCreate.ShopName))
            {
                string err = string.Format("The shop name '{0}' already exists... sorry. Try again.", shopCreate.ShopName);
                throw new Exception(err);
            }
            //create the shop
            //get the shop Child Product
            ProductChild shop = ProductChildBiz.FindForName(ProductChild.GetShopName());

            shop.IsNullThrowException("Shop not found");

            Owner ownerProductChild = shop.Owner;

            ownerProductChild.IsNullThrowException("No Product Child Owner");

            quantity = shopCreate.NoOfMonths;
            if (quantity == 0)
            {
                throw new Exception("The quantity is zero. This is not allowed");
            }

            Customer customerUser = getCustomerOfUser();

            SelectList selectListOwner      = null;
            SelectList selectListCustomer   = null;
            SelectList selectListBillTo     = null;
            SelectList selectListShipTo     = null;
            string     addressBillToId      = "";
            string     addressShipToId      = "";
            decimal    salePrice            = MenuPathMain.Payment_To_Buy_Shop();
            DateTime   expectedDeliveryDate = DateTime.Now;
            DateTime   guaranteePeriodEnds  = DateTime.Now;

            //MenuPathMain mpm = MenuPathMainBiz.Find(shopCreate.MenuPathMainId);
            //mpm.IsNullThrowException("Menu Path Main is null");

            mpm     = getMainMenuPath(shopCreate);
            product = setup_Product_For_Shop(shopCreate, userOwner);

            string shopId = product.Id;

            BuySellDoc sale = CreateSale(
                shop,
                ownerProductChild,
                quantity,
                salePrice,
                customerUser,
                selectListOwner,
                selectListCustomer,
                addressBillToId,
                addressShipToId,
                selectListBillTo,
                selectListShipTo,
                BuySellDocStateENUM.RequestUnconfirmed,
                BuySellDocStateModifierENUM.Accept,
                expectedDeliveryDate,
                guaranteePeriodEnds,
                shopId);

            product.BuySellDocs.Add(sale);

            parm = new ControllerCreateEditParameter(
                product as ICommonWithId,
                httpMiscUploadedFiles,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                MenuENUM.EditDefault,
                UserName,
                UserId,
                shopCreate.ReturnUrl,
                GetGlobalObject(),
                button);

            return(parm);
        }
Exemple #12
0
        public async Task <ShopCreatedSuccessfullyVM> Setup_To_Create_Shop_Post_Async(ShopVM shopCreate, string button, HttpPostedFileBase[] httpMiscUploadedFiles)
        {
            UserId.IsNullOrWhiteSpaceThrowException("You are not logged in.");
            shopCreate.MenuPathMainId.IsNullOrWhiteSpaceThrowException("Main Menu Path not received");
            Owner userOwner = OwnerBiz.GetPlayerFor(UserId);

            userOwner.IsNullThrowException("You are not authourized to create a shop. Please become a seller first.");

            if (button == "accept")
            {
                //CashDistributionEngine cde;
                //int quantity;
                //Product product;
                //MenuPathMain mpm;
                //ControllerCreateEditParameter parm = setup_Shop_Into_ControllerCreateEditParameter(shopCreate, button, httpMiscUploadedFiles, userOwner, out cde, out quantity, out product, out mpm, out parm);

                decimal paymentAmount = MenuPathMain.Payment_To_Buy_Shop();
                decimal commissionPct = BuySellDoc.Get_Maximum_Commission_Product_Percent();
                bool    isNonRefundablePaymentAllowed = true;
                CashDistributionEngine cde            = get_CashDistributionEngineAndCheckBalance(paymentAmount, isNonRefundablePaymentAllowed);

                //check the name, if it is already used, throw error and return to create screen
                if (isShopNameExists(shopCreate.ShopName))
                {
                    string err = string.Format("The shop name '{0}' already exists... sorry. Try again.", shopCreate.ShopName);
                    throw new Exception(err);
                }
                //create the shop


                int quantity = shopCreate.NoOfMonths;
                if (quantity == 0)
                {
                    throw new Exception("The quantity is zero. This is not allowed");
                }

                Customer   customerUser         = getCustomerOfUser();
                SelectList selectListOwner      = null;
                SelectList selectListCustomer   = null;
                SelectList selectListBillTo     = null;
                SelectList selectListShipTo     = null;
                string     addressBillToId      = "";
                string     addressShipToId      = "";
                decimal    salePrice            = MenuPathMain.Payment_To_Buy_Shop();
                DateTime   expectedDeliveryDate = DateTime.Now;
                DateTime   guaranteePeriodEnds  = DateTime.Now;

                //MenuPathMain mpm = MenuPathMainBiz.Find(shopCreate.MenuPathMainId);
                //mpm.IsNullThrowException("Menu Path Main is null");

                MenuPathMain mpm     = getMainMenuPath(shopCreate);
                Product      product = setup_Product_For_Shop(shopCreate, userOwner);

                //get the shop Child Product
                ProductChild shopBuySellItem = ProductChildBiz.FindForName(ProductChild.GetShopName());
                shopBuySellItem.IsNullThrowException("Shop not found");

                string shopId = product.Id;
                Owner  ownerOfProductChild = shopBuySellItem.Owner;
                ownerOfProductChild.IsNullThrowException("No Product Child Owner");

                BuySellDoc sale = CreateSale(
                    shopBuySellItem,
                    ownerOfProductChild,
                    quantity,
                    salePrice,
                    customerUser,
                    selectListOwner,
                    selectListCustomer,
                    addressBillToId,
                    addressShipToId,
                    selectListBillTo,
                    selectListShipTo,
                    BuySellDocStateENUM.RequestUnconfirmed,
                    BuySellDocStateModifierENUM.Accept,
                    expectedDeliveryDate,
                    guaranteePeriodEnds,
                    shopId);

                product.BuySellDocs.Add(sale);

                ControllerCreateEditParameter parm = new ControllerCreateEditParameter(
                    product as ICommonWithId,
                    httpMiscUploadedFiles,
                    null,
                    null,
                    null,
                    null,
                    null,
                    null,
                    null,
                    MenuENUM.EditDefault,
                    UserName,
                    UserId,
                    shopCreate.ReturnUrl,
                    GetGlobalObject(),
                    button);

                await ShopBiz.CreateAndSaveAsync(parm);


                decimal  refundable_Spent    = cde.Refundable_Final;
                decimal  nonRefundable_spent = cde.NonRefundable_Final;
                string   shopName            = product.FullName();
                string   mp1Name             = mpm.MenuPath1.FullName();
                string   mp2Name             = mpm.MenuPath2.FullName();
                string   mp3Name             = mpm.MenuPath3.FullName();
                int      numberOfMonths      = quantity;
                DateTime expiryDate          = product.ShopExpiryDate.Date_NotNull_Min;

                ShopCreatedSuccessfullyVM shopCreatedSuccessfully = new ShopCreatedSuccessfullyVM(
                    refundable_Spent,
                    nonRefundable_spent,
                    shopName,
                    mp1Name,
                    mp2Name,
                    mp3Name,
                    numberOfMonths,
                    expiryDate,
                    shopCreate.ReturnUrl);

                //BuySellDocBiz.SaveChanges();
                return(shopCreatedSuccessfully);
            }
            else
            {
                string err = string.Format("You caneled the operation.");
                throw new Exception(err);
            }
        }
Exemple #13
0
        public async Task <ShopCreatedSuccessfullyVM> Setup_To_Edit_Shop_Post_Async(ShopVM shopVm, string button, HttpPostedFileBase[] httpMiscUploadedFiles)
        {
            UserId.IsNullOrWhiteSpaceThrowException("You are not logged in.");
            shopVm.IsNullThrowExceptionArgument("Shop");
            button.IsNullOrWhiteSpaceThrowArgumentException("button");
            Owner userOwner = OwnerBiz.GetPlayerFor(UserId);

            userOwner.IsNullThrowException("You are not authourized to create a shop. Please become a seller first.");
            if (button == "accept")
            {
                //locate the shop

                if (shopVm.NoOfMonths == 0)
                {
                    throw new Exception("No of months is zero");
                }
                decimal salePrice = MenuPathMain.Payment_To_Buy_Shop();
                int     quantity  = shopVm.NoOfMonths;

                //see if User has the money to do what they want.
                decimal paymentAmount = salePrice * quantity;

                bool isNonRefundablePaymentAllowed = true;
                CashDistributionEngine cde         = get_CashDistributionEngineAndCheckBalance(paymentAmount, isNonRefundablePaymentAllowed);

                //get the shop Child Product
                ProductChild shopBuySellItem = ProductChildBiz.FindForName(ProductChild.GetShopName());
                shopBuySellItem.IsNullThrowException("Shop not found");

                Owner ownerOfProductChild = shopBuySellItem.Owner;
                ownerOfProductChild.IsNullThrowException("No Product Child Owner");

                Customer customerUser = getCustomerOfUser();

                Product product = ProductBiz.Find(shopVm.Id);
                product.IsNullThrowException("product");
                string shopId = product.Id;
                updateTheProductFromTheShopVm(product, shopVm);

                SelectList selectListOwner      = null;
                SelectList selectListCustomer   = null;
                SelectList selectListBillTo     = null;
                SelectList selectListShipTo     = null;
                string     addressBillToId      = "";
                string     addressShipToId      = "";
                DateTime   expectedDeliveryDate = DateTime.Now;
                DateTime   guaranteePeriodEnds  = DateTime.Now;


                BuySellDoc sale = CreateSale(
                    shopBuySellItem,
                    ownerOfProductChild,
                    quantity,
                    salePrice,
                    customerUser,
                    selectListOwner,
                    selectListCustomer,
                    addressBillToId,
                    addressShipToId,
                    selectListBillTo,
                    selectListShipTo,
                    BuySellDocStateENUM.RequestUnconfirmed,
                    BuySellDocStateModifierENUM.Accept,
                    expectedDeliveryDate,
                    guaranteePeriodEnds,
                    shopId);

                product.BuySellDocs.Add(sale);

                ControllerCreateEditParameter parm = new ControllerCreateEditParameter(
                    product as ICommonWithId,
                    httpMiscUploadedFiles,
                    null,
                    null,
                    null,
                    null,
                    null,
                    null,
                    null,
                    MenuENUM.EditDefault,
                    UserName,
                    UserId,
                    shopVm.ReturnUrl,
                    null, //globalObject not required for products
                    button);

                await ProductBiz.UpdateAndSaveAsync(parm);


                MenuPathMain mpm = product.MenuPathMains_Fixed.FirstOrDefault();

                decimal  refundable_Spent    = cde.Refundable_Final;
                decimal  nonRefundable_spent = cde.NonRefundable_Final;
                string   shopName            = product.FullName();
                string   mp1Name             = mpm.MenuPath1.FullName();
                string   mp2Name             = mpm.MenuPath2.FullName();
                string   mp3Name             = mpm.MenuPath3.FullName();
                int      numberOfMonths      = quantity;
                DateTime expiryDate          = product.ShopExpiryDate.Date_NotNull_Min;

                ShopCreatedSuccessfullyVM shopCreatedSuccessfully = new ShopCreatedSuccessfullyVM(
                    refundable_Spent,
                    nonRefundable_spent,
                    shopName,
                    mp1Name,
                    mp2Name,
                    mp3Name,
                    numberOfMonths,
                    expiryDate,
                    shopVm.ReturnUrl);

                return(shopCreatedSuccessfully);
            }

            return(null);
        }