public bool CancelAccount(LoginViewModel settingForm, out string outputMessage)
        {
            string  emailAddress = HttpContext.Current.User.Identity.Name.ToString();
            Account userAccount  = global.GetAccount(emailAddress);

            if (userAccount != null)
            {
                string emailUsername = settingForm.EmailAddress.ToLower();
                string setPassword   = Crypto.SHA1(settingForm.Password);
                if ((userAccount.EmailAddress.ToLower() == emailUsername || userAccount.Username.ToLower() == emailUsername) && userAccount.Password == setPassword)
                {
                    AccountDetail userDetails = db.AccountDetail.Where(ad => ad.AccountId == userAccount.AccountId).FirstOrDefault();
                    if (userDetails != null)
                    {
                        List <Item> relatedItems = db.Item.Where(i => i.AccountId == userAccount.AccountId).ToList();
                        if (relatedItems != null)
                        {
                            foreach (Item item in relatedItems)
                            {
                                ItemDetail detail = db.ItemDetail.Where(d => d.ItemId == item.ItemId && d.ItemStatus != (int)ItemStatusType.Confirmed).FirstOrDefault();
                                if (detail != null)
                                {
                                    List <Wishlist> wishes = db.Wishlist.Where(w => w.ItemId == item.ItemId).ToList();
                                    if (wishes != null)
                                    {
                                        db.Wishlist.RemoveRange(wishes).ToList();
                                        db.SaveChanges();
                                    }
                                    tradeManager.DeleteOffersByItem(item);
                                    db.Item.Remove(item);
                                }
                            }
                            db.SaveChanges();
                        }
                        List <Notification> notes = db.Notification.Where(n => n.AccountId == userAccount.AccountId).ToList();
                        if (notes != null)
                        {
                            db.Notification.RemoveRange(notes);
                            db.SaveChanges();
                        }
                        userDetails.AccountStatus = (int)AccountStatusType.Cancelled;
                        db.SaveChanges();
                        outputMessage = Resources.Processing.ProcessAccountRemoved;
                        return(true);
                    }
                }
                else
                {
                    outputMessage = Resources.Processing.ProcessIncorrectLogin;
                    return(false);
                }
            }
            outputMessage = Resources.Processing.ProcessError;
            return(false);
        }
        public bool DeleteItem(int itemId, out string outputMessage)
        {
            string emailAddress = HttpContext.Current.User.Identity.Name.ToString();

            if (!global.IsUniqueEmailAddress(emailAddress))
            {
                Account userAccount = global.GetAccount(emailAddress);
                try
                {
                    Item referenceItem = (userAccount != null) ? db.Item.Where(i => i.ItemId == itemId && i.AccountId == userAccount.AccountId).FirstOrDefault() : null;
                    if (referenceItem != null)
                    {
                        bool deleteReferenceTrades = tradeManager.DeleteOffersByItem(referenceItem);

                        List <Wishlist> referenceWishlists = db.Wishlist.Where(w => w.ItemId == referenceItem.ItemId).ToList();
                        if (referenceWishlists != null)
                        {
                            db.Wishlist.RemoveRange(referenceWishlists);
                            db.SaveChanges();
                        }

                        imaging.DeleteImage(referenceItem.ItemId);

                        RedirectViewModel redirect = new RedirectViewModel("Index", "Items", "");
                        SaveNotification(referenceItem, redirect, NotificationType.DeleteItem);
                        db.Item.Remove(referenceItem);
                        db.SaveChanges();

                        outputMessage = "Your item has been deleted.";
                        return(true);
                    }
                }
                catch
                {
                    outputMessage = Resources.Processing.ProcessError;
                }
            }
            outputMessage = Resources.Processing.ProcessError;
            return(false);
        }
        public int RemoveReportable(int reportId)
        {
            Report findReport = db.Report.Find(reportId);

            if (findReport != null)
            {
                int referenceType = findReport.ReportableType;
                if (referenceType == (int)ReportType.Item)
                {
                    ItemDetail reportableDetail = db.ItemDetail.Where(d => d.ItemId == findReport.ReportableId && d.ItemStatus != (int)ItemStatusType.Confirmed).FirstOrDefault();
                    if (reportableDetail != null)
                    {
                        Item reportable = db.Item.Where(i => i.ItemId == reportableDetail.ItemId).FirstOrDefault();
                        if (reportable != null)
                        {
                            List <Wishlist> wishes = db.Wishlist.Where(w => w.ItemId == reportable.ItemId).ToList();
                            if (wishes != null)
                            {
                                db.Wishlist.RemoveRange(wishes).ToList();
                                db.SaveChanges();
                            }
                            List <Report> remainingReports = db.Report.Where(r => r.ReportableId == reportable.ItemId && r.ReportableType == (int)ReportType.Item && r.ReportId != findReport.ReportId).ToList();
                            if (remainingReports != null)
                            {
                                db.Report.RemoveRange(remainingReports).ToList();
                                db.SaveChanges();
                            }
                            tradeManager.DeleteOffersByItem(reportable);
                            db.Item.Remove(reportable);
                            db.SaveChanges();
                        }
                    }
                    db.Report.Remove(findReport);
                    db.SaveChanges();
                    return(referenceType);
                }
                else
                {
                    Account reportableAccount = db.Account.Where(a => a.AccountId == findReport.ReportableId).FirstOrDefault();
                    if (reportableAccount != null)
                    {
                        AccountDetail userDetails = db.AccountDetail.Where(ad => ad.AccountId == reportableAccount.AccountId).FirstOrDefault();
                        if (userDetails != null)
                        {
                            List <Item> relatedItems = db.Item.Where(i => i.AccountId == reportableAccount.AccountId).ToList();
                            if (relatedItems != null)
                            {
                                foreach (Item item in relatedItems)
                                {
                                    ItemDetail detail = db.ItemDetail.Where(d => d.ItemId == item.ItemId && d.ItemStatus != (int)ItemStatusType.Confirmed).FirstOrDefault();
                                    if (detail != null)
                                    {
                                        List <Wishlist> wishes = db.Wishlist.Where(w => w.ItemId == item.ItemId).ToList();
                                        if (wishes != null)
                                        {
                                            db.Wishlist.RemoveRange(wishes).ToList();
                                            db.SaveChanges();
                                        }
                                        List <Report> remainingReports = db.Report.Where(r => r.ReportableId == item.ItemId && r.ReportableType == (int)ReportType.Item && r.ReportId != findReport.ReportId).ToList();
                                        if (remainingReports != null)
                                        {
                                            db.Report.RemoveRange(remainingReports).ToList();
                                            db.SaveChanges();
                                        }
                                        tradeManager.DeleteOffersByItem(item);
                                        db.Item.Remove(item);
                                        db.SaveChanges();
                                    }
                                }
                            }
                            userDetails.AccountStatus = (int)AccountStatusType.Cancelled;
                            db.SaveChanges();
                        }
                    }
                    db.Report.Remove(findReport);
                    db.SaveChanges();
                    return(referenceType);
                }
            }
            return(-1);
        }