Exemplo n.º 1
0
        public DashboardViewModel CreateDashboard()
        {
            string  emailAddress = HttpContext.Current.User.Identity.Name.ToString();
            Account checkAccount = global.GetAccount(emailAddress);

            if (checkAccount != null)
            {
                DashboardViewModel newDashboard = new DashboardViewModel();
                newDashboard.Username      = checkAccount.Username;
                newDashboard.Notifications = CreateNotificationList();
                return(newDashboard);
            }
            return(null);
        }
Exemplo n.º 2
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);
        }
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 UploadFormViewModel EditUploadForm(int itemId)
        {
            string emailAddress = HttpContext.Current.User.Identity.Name.ToString();

            if (!global.IsUniqueEmailAddress(emailAddress))
            {
                Account userAccount   = global.GetAccount(emailAddress);
                Item    referenceItem = (userAccount != null) ? db.Item.Where(i => i.ItemId == itemId && i.AccountId == userAccount.AccountId).FirstOrDefault() : null;
                if (referenceItem != null)
                {
                    UploadFormViewModel newForm = new UploadFormViewModel();
                    newForm.Name        = referenceItem.Name;
                    newForm.Caption     = referenceItem.Caption;
                    newForm.Description = referenceItem.Description;
                    Image itemImage = imaging.ServeImage(referenceItem);
                    if (itemImage != null)
                    {
                        newForm.ImageString = itemImage.ImageSource;
                        newForm.ImageKeep   = 1;
                    }
                    newForm.CategoriesList = global.GetCategoryList();
                    if (newForm.CategoriesList == null)
                    {
                        return(null);
                    }
                    newForm.SubcategoriesList = global.GetSubCategoryList();
                    newForm.ReferenceAction   = "Edit";
                    newForm.ReferenceId       = itemId;
                    return(newForm);
                }
            }
            return(null);
        }
        public bool ChangeUsername(SettingUsernameViewModel settingForm, out string outputMessage)
        {
            string  emailAddress = HttpContext.Current.User.Identity.Name.ToString();
            Account userAccount  = global.GetAccount(emailAddress);

            if (userAccount != null)
            {
                if (userAccount.Username.ToLower() == settingForm.OldUsername.ToLower())
                {
                    if (global.IsUniqueUsername(settingForm.NewUsername))
                    {
                        try
                        {
                            userAccount.Username = settingForm.NewUsername;
                            db.SaveChanges();
                            outputMessage = string.Format(Resources.Processing.ProcessSettingsConfirmed, "username");
                            return(true);
                        }
                        catch
                        {
                            outputMessage = Resources.Processing.ProcessError;
                            return(false);
                        }
                    }
                    else
                    {
                        outputMessage = Resources.Processing.ProcessUsernameExists;
                        return(false);
                    }
                }
                else
                {
                    outputMessage = Resources.Processing.ProcessUsernameNotFound;
                    return(false);
                }
            }
            outputMessage = Resources.Processing.ProcessError;
            return(false);
        }
Exemplo n.º 6
0
        public bool CheckAccountLevel()
        {
            string  emailAddress = HttpContext.Current.User.Identity.Name.ToString();
            Account userAccount  = global.GetAccount(emailAddress);

            if (userAccount != null)
            {
                AccountDetail userDetail = db.AccountDetail.Where(ad => ad.AccountId == userAccount.AccountId).FirstOrDefault();
                if (userDetail != null)
                {
                    if (userDetail.AccountLevel == (int)AccountLevelType.Admin)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
        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);
        }
        public bool SendReport(ReportViewModel reportForm, ReportType type, out string outputMessage)
        {
            string  emailAddress = HttpContext.Current.User.Identity.Name.ToString();
            Account checkAccount = global.GetAccount(emailAddress);

            if (type == ReportType.Item)
            {
                Item getItem = db.Item.Where(i => i.ItemId == reportForm.ReferenceId).FirstOrDefault();
                if (getItem != null)
                {
                    Account getAccount = db.Account.Where(a => a.AccountId == getItem.AccountId).FirstOrDefault();
                    if (getAccount != null)
                    {
                        Report checkExisting = db.Report.Where(r => r.ReportableId == getItem.ItemId && r.ReportableType == (int)ReportType.Item && r.AccountId == checkAccount.AccountId).FirstOrDefault();
                        if (checkExisting == null)
                        {
                            ItemDetail getItemDetail = db.ItemDetail.Where(d => d.ItemId == getItem.ItemId).FirstOrDefault();
                            if (getItemDetail != null)
                            {
                                getItemDetail.Reported = 1;
                                db.SaveChanges();
                            }
                            try
                            {
                                Report newReport = new Report();
                                newReport.Description    = reportForm.ReportDetails;
                                newReport.ReportableId   = getItem.ItemId;
                                newReport.ReportableType = (int)ReportType.Item;
                                newReport.AccountId      = checkAccount.AccountId;
                                db.Report.Add(newReport);
                                db.SaveChanges();
                                outputMessage = Resources.Processing.ProcessReportSent;
                                return(true);
                            }
                            catch
                            {
                                outputMessage = Resources.Processing.ProcessError;
                                return(false);
                            }
                        }
                        else
                        {
                            outputMessage = Resources.Processing.ProcessReportExists;
                            return(false);
                        }
                    }
                }
            }
            else
            {
                Account getAccount = db.Account.Where(a => a.AccountId == reportForm.ReferenceId).FirstOrDefault();
                if (getAccount != null)
                {
                    Report checkExisting = db.Report.Where(r => r.ReportableId == getAccount.AccountId && r.ReportableType == (int)ReportType.Account && r.AccountId == checkAccount.AccountId).FirstOrDefault();
                    if (checkExisting == null)
                    {
                        AccountDetail getAccountDetail = db.AccountDetail.Where(d => d.AccountId == getAccount.AccountId).FirstOrDefault();
                        if (getAccountDetail != null)
                        {
                            getAccountDetail.AccountStatus = (int)AccountStatusType.Reported;
                            db.SaveChanges();
                        }
                        try
                        {
                            Report newReport = new Report();
                            newReport.Description    = reportForm.ReportDetails;
                            newReport.ReportableId   = getAccount.AccountId;
                            newReport.ReportableType = (int)ReportType.Account;
                            newReport.AccountId      = checkAccount.AccountId;
                            db.Report.Add(newReport);
                            db.SaveChanges();
                            outputMessage = Resources.Processing.ProcessReportSent;
                            return(true);
                        }
                        catch
                        {
                            outputMessage = Resources.Processing.ProcessError;
                            return(false);
                        }
                    }
                    else
                    {
                        outputMessage = Resources.Processing.ProcessReportExists;
                        return(false);
                    }
                }
            }
            outputMessage = Resources.Processing.ProcessError;
            return(false);
        }