Esempio n. 1
0
        public ActionResult GetAgreement(string id)
        {
            var fileHelper = new RentalAgreements();

            if (String.IsNullOrEmpty(id))
            {
                return(RedirectToAction("GetAllAgreements"));
            }

            var agreementQuery = db.Users.Find(User.Identity.Name).Agreements.Where(a => a.Id == id);

            if (agreementQuery == null || agreementQuery.Count() == 0)
            {
                return(HttpNotFound());
            }

            var findAgreement = agreementQuery.ToList()[0];

            return(File(fileHelper.Download(findAgreement.FileName, User.Identity.Name, HttpContext), findAgreement.ContentType));
        }
Esempio n. 2
0
        public ActionResult UploadAgreement()
        {
            var       resultList    = new List <FilesStatus>();
            var       filesToUpload = this.HttpContext.Request.Files;
            var       uploadHelper  = new RentalAgreements();
            Agreement newAgreement;

            for (int i = 0; i < filesToUpload.Count; i++)
            {
                newAgreement = uploadHelper.Upload(filesToUpload[i], User.Identity.Name, HttpContext);
                if (newAgreement != null)
                {
                    var status = new FilesStatus()
                    {
                        thumbnail_url = Url.Content("~/User/GetThumb/") + newAgreement.Id,
                        url           = Url.Content("~/User/GetAgreement/") + newAgreement.Id,
                        name          = newAgreement.FileName,
                        size          = filesToUpload[i].ContentLength,
                        type          = filesToUpload[i].ContentType,
                        delete_url    = Url.Content("~/User/DeleteAgreement/") + newAgreement.Id,
                        delete_type   = "POST",
                        progress      = "1.0"
                    };

                    resultList.Add(status);

                    db.Agreements.Add(newAgreement);
                    db.SaveChanges();
                }
            }

            var resultStatus = new UploadRentalAgreementViewModel()
            {
                Status = resultList
            };

            return(Json(resultList));
        }
Esempio n. 3
0
        public void DeleteAgreement(string id)
        {
            var fileHelper = new RentalAgreements();

            if (String.IsNullOrEmpty(id))
            {
                fileHelper.DeleteAll(User.Identity.Name, HttpContext);
                foreach (Agreement a in db.Agreements.ToList())
                {
                    db.Entry(a).State = EntityState.Deleted;
                }
            }
            else
            {
                var agreement = db.Agreements.Find(id);
                if (agreement != null)
                {
                    fileHelper.Delete(agreement.FileName, User.Identity.Name, HttpContext);
                    db.Entry(agreement).State = EntityState.Deleted;
                }
            }

            db.SaveChanges();
        }
Esempio n. 4
0
        /// <summary>
        /// Gets the hash code
        /// </summary>
        /// <returns>Hash code</returns>
        public override int GetHashCode()
        {
            // credit: http://stackoverflow.com/a/263416/677735
            unchecked // Overflow is fine, just wrap
            {
                int hash = 41;

                // Suitable nullity checks
                hash = hash * 59 + Id.GetHashCode();

                if (District != null)
                {
                    hash = hash * 59 + District.GetHashCode();
                }

                if (Name != null)
                {
                    hash = hash * 59 + Name.GetHashCode();
                }

                if (Status != null)
                {
                    hash = hash * 59 + Status.GetHashCode();
                }

                if (ProvincialProjectNumber != null)
                {
                    hash = hash * 59 + ProvincialProjectNumber.GetHashCode();
                }

                if (Information != null)
                {
                    hash = hash * 59 + Information.GetHashCode();
                }

                if (RentalRequests != null)
                {
                    hash = hash * 59 + RentalRequests.GetHashCode();
                }

                if (RentalAgreements != null)
                {
                    hash = hash * 59 + RentalAgreements.GetHashCode();
                }

                if (PrimaryContact != null)
                {
                    hash = hash * 59 + PrimaryContact.GetHashCode();
                }

                if (Contacts != null)
                {
                    hash = hash * 59 + Contacts.GetHashCode();
                }

                if (Notes != null)
                {
                    hash = hash * 59 + Notes.GetHashCode();
                }

                if (Attachments != null)
                {
                    hash = hash * 59 + Attachments.GetHashCode();
                }

                if (History != null)
                {
                    hash = hash * 59 + History.GetHashCode();
                }

                return(hash);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Returns true if Project instances are equal
        /// </summary>
        /// <param name="other">Instance of Project to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(Project other)
        {
            if (other is null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Id == other.Id ||
                     Id.Equals(other.Id)
                     ) &&
                 (
                     District == other.District ||
                     District != null &&
                     District.Equals(other.District)
                 ) &&
                 (
                     Name == other.Name ||
                     Name != null &&
                     Name.Equals(other.Name)
                 ) &&
                 (
                     Status == other.Status ||
                     Status != null &&
                     Status.Equals(other.Status)
                 ) &&
                 (
                     ProvincialProjectNumber == other.ProvincialProjectNumber ||
                     ProvincialProjectNumber != null &&
                     ProvincialProjectNumber.Equals(other.ProvincialProjectNumber)
                 ) &&
                 (
                     Information == other.Information ||
                     Information != null &&
                     Information.Equals(other.Information)
                 ) &&
                 (
                     RentalRequests == other.RentalRequests ||
                     RentalRequests != null &&
                     RentalRequests.SequenceEqual(other.RentalRequests)
                 ) &&
                 (
                     RentalAgreements == other.RentalAgreements ||
                     RentalAgreements != null &&
                     RentalAgreements.SequenceEqual(other.RentalAgreements)
                 ) &&
                 (
                     PrimaryContact == other.PrimaryContact ||
                     PrimaryContact != null &&
                     PrimaryContact.Equals(other.PrimaryContact)
                 ) &&
                 (
                     Contacts == other.Contacts ||
                     Contacts != null &&
                     Contacts.SequenceEqual(other.Contacts)
                 ) &&
                 (
                     Notes == other.Notes ||
                     Notes != null &&
                     Notes.SequenceEqual(other.Notes)
                 ) &&
                 (
                     Attachments == other.Attachments ||
                     Attachments != null &&
                     Attachments.SequenceEqual(other.Attachments)
                 ) &&
                 (
                     History == other.History ||
                     History != null &&
                     History.SequenceEqual(other.History)
                 ));
        }