Exemplo n.º 1
0
        public bool CreateOffer(int referenceA, int referenceB)
        {
            string emailAddress = HttpContext.Current.User.Identity.Name.ToString();

            if (!global.IsUniqueEmailAddress(emailAddress))
            {
                Account userAccount = global.GetAccount(emailAddress);
                try
                {
                    Item receiverItem = db.Item.Where(i => i.ItemId == referenceA).FirstOrDefault();
                    Item senderItem   = db.Item.Where(i => i.ItemId == referenceB && i.AccountId == userAccount.AccountId).FirstOrDefault();
                    if (receiverItem != null && senderItem != null)
                    {
                        Offer newOffer = new Offer();
                        newOffer.AccountId      = userAccount.AccountId;
                        newOffer.SenderItemId   = senderItem.ItemId;
                        newOffer.ReceiverId     = receiverItem.AccountId;
                        newOffer.ReceiverItemId = receiverItem.ItemId;
                        db.Offer.Add(newOffer);
                        db.SaveChanges();

                        OfferDetail newDetail = new OfferDetail();
                        newDetail.OfferId        = newOffer.OfferId;
                        newDetail.Confirmed      = 0;
                        newDetail.UploadDate     = DateTime.Now;
                        newDetail.ExpirationDate = DateTime.Now.AddDays(14);
                        db.OfferDetail.Add(newDetail);
                        db.SaveChanges();

                        RedirectViewModel redirectSender   = new RedirectViewModel("Index", "Trades", "");
                        RedirectViewModel redirectReceiver = new RedirectViewModel("UserOffers", "Trades", "");
                        SaveNotification(newOffer, redirectSender, NotificationType.AddTradeSender);
                        SaveNotification(newOffer, redirectReceiver, NotificationType.AddTradeReceiver);
                        return(true);
                    }
                }
                catch
                {
                    return(false);
                }
            }
            return(false);
        }
        public UploadFormViewModel NewUploadForm()
        {
            string emailAddress = HttpContext.Current.User.Identity.Name.ToString();

            if (!global.IsUniqueEmailAddress(emailAddress))
            {
                UploadFormViewModel newForm = new UploadFormViewModel();
                newForm.CategoriesList = global.GetCategoryList();
                if (newForm.CategoriesList == null)
                {
                    return(null);
                }
                newForm.SubcategoriesList = global.GetSubCategoryList();
                newForm.ReferenceAction   = "Upload";
                newForm.ReferenceId       = 0;
                return(newForm);
            }
            return(null);
        }
Exemplo n.º 3
0
        public SearchFormViewModel NewSearchForm()
        {
            string emailAddress = HttpContext.Current.User.Identity.Name.ToString();

            if (!global.IsUniqueEmailAddress(emailAddress))
            {
                Account             userAccount = global.GetAccount(emailAddress);
                SearchFormViewModel newForm     = new SearchFormViewModel(userAccount.State);
                newForm.CategoriesList = global.GetCategoryList();
                newForm.City           = userAccount.City;
                if (newForm.CategoriesList == null)
                {
                    return(null);
                }
                newForm.SubcategoriesList = global.GetSubCategoryList();
                return(newForm);
            }
            return(null);
        }
        public IEnumerable <ItemBulletinViewModel> GetItemList()
        {
            string emailAddress = HttpContext.Current.User.Identity.Name.ToString();

            if (!global.IsUniqueEmailAddress(emailAddress))
            {
                Account userAccount = global.GetAccount(emailAddress);
                List <ItemBulletinViewModel> itemList    = new List <ItemBulletinViewModel>();
                IEnumerable <Item>           itemResults = db.Item.Where(i => i.AccountId == userAccount.AccountId).ToList();
                if (itemResults != null)
                {
                    ItemBulletinViewModel writeModel;
                    foreach (Item i in itemResults)
                    {
                        bool check = global.isConfirmedItem(i);
                        writeModel             = new ItemBulletinViewModel();
                        writeModel.ItemId      = i.ItemId;
                        writeModel.Name        = i.Name;
                        writeModel.Caption     = i.Caption;
                        writeModel.Description = i.Description;
                        Image itemImage = imaging.ServeImage(i);
                        if (itemImage != null)
                        {
                            writeModel.ImageSource = itemImage.ImageSource;
                        }
                        if (check)
                        {
                            writeModel.Status = 1;
                        }
                        itemList.Add(writeModel);
                    }
                }
                return(itemList);
            }
            return(null);
        }
Exemplo n.º 5
0
        public bool CreateAccount(RegisterViewModel newAccount, out string outputMessage)
        {
            if (!global.IsUniqueEmailAddress(newAccount.EmailAddress))
            {
                outputMessage = Resources.Processing.ProcessEmailExists;
                return(false);
            }
            if (!global.IsUniqueUsername(newAccount.Username))
            {
                outputMessage = Resources.Processing.ProcessUsernameExists;
                return(false);
            }

            Account registerAccount = new Account();

            registerAccount.EmailAddress = newAccount.EmailAddress.ToLower();
            registerAccount.Username     = newAccount.Username;
            registerAccount.Password     = Crypto.SHA1(newAccount.Password);;
            registerAccount.ContactName  = newAccount.ContactName;
            registerAccount.Country      = (newAccount.Country != null) ? newAccount.Country : "Canada";
            registerAccount.State        = (newAccount.State != null) ? newAccount.State : "ON";
            registerAccount.City         = newAccount.City;
            registerAccount.Phone        = newAccount.Phone;
            db.Account.Add(registerAccount);
            db.SaveChanges();

            AccountDetail registerDetails = new AccountDetail();

            registerDetails.AccountId         = registerAccount.AccountId;
            registerDetails.AccountLevel      = 1;
            registerDetails.AccountStatus     = 1;
            registerDetails.SecurityQuestionA = newAccount.SecurityQuestionA;
            registerDetails.SecurityQuestionB = newAccount.SecurityQuestionB;
            registerDetails.SecurityAnswerA   = newAccount.SecurityAnswerA;
            registerDetails.SecurityAnswerB   = newAccount.SecurityAnswerB;
            db.AccountDetail.Add(registerDetails);
            db.SaveChanges();

            outputMessage = newAccount.Username + " is now registered";
            return(true);
        }
        public bool ChangeEmail(SettingEmailViewModel settingForm, out string outputMessage)
        {
            string  emailAddress = HttpContext.Current.User.Identity.Name.ToString();
            Account userAccount  = global.GetAccount(emailAddress);

            if (userAccount != null)
            {
                if (userAccount.EmailAddress.ToLower() == settingForm.OldEmail.ToLower())
                {
                    if (global.IsUniqueEmailAddress(settingForm.NewEmail))
                    {
                        try
                        {
                            userAccount.EmailAddress = settingForm.NewEmail;
                            db.SaveChanges();
                            outputMessage = string.Format(Resources.Processing.ProcessSettingsConfirmed, "email address");
                            return(true);
                        }
                        catch
                        {
                            outputMessage = Resources.Processing.ProcessError;
                            return(false);
                        }
                    }
                    else
                    {
                        outputMessage = Resources.Processing.ProcessEmailExists;
                        return(false);
                    }
                }
                else
                {
                    outputMessage = Resources.Processing.ProcessEmailNotFound;
                    return(false);
                }
            }
            outputMessage = Resources.Processing.ProcessError;
            return(false);
        }