public static bool ChangePassword(string username, string password)
        {
            try
            {
                User existingUser = new User();
                using (var context = new PropertyDBEntities())
                {
                    existingUser = context.Users
                                    .Where(t => t.Username == username)
                                    .FirstOrDefault();
                }

                if (existingUser != null)
                {
                    existingUser.Password = password;
                    existingUser.FirstTime = false;
                    using (var context = new PropertyDBEntities())
                    {
                        context.Entry(existingUser).State = EntityState.Modified;

                        context.SaveChanges();
                    }

                    return true;
                }
                else
                {
                    return false;
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static bool UpdatePropertyAsSold(PropertyDetail propertyDetails)
        {
            try
            {
                PropertyDetail existingPropertyDetails = new PropertyDetail();
                using (var context = new PropertyDBEntities())
                {
                    existingPropertyDetails = context.PropertyDetails.Include("PropertyImages")
                                    .Where(t => t.PropertyID == propertyDetails.PropertyID)
                                    .FirstOrDefault();
                }

                if (existingPropertyDetails != null)
                {
                    existingPropertyDetails.Status = propertyDetails.Status;

                    using (var context = new PropertyDBEntities())
                    {
                        context.Entry(existingPropertyDetails).State = EntityState.Modified;
                        context.SaveChanges();
                    }
                    return true;
                }
                else
                {
                    return false;
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static bool Update(MailTemplate mailTemplate)
        {
            try
            {
                MailTemplate existingMailTemplate = new MailTemplate();
                using (var context = new PropertyDBEntities())
                {
                    existingMailTemplate = context.MailTemplates
                                    .Where(t => t.ID == mailTemplate.ID)
                                    .FirstOrDefault();
                }

                if (existingMailTemplate != null)
                {
                    existingMailTemplate.Body = mailTemplate.Body;
                    existingMailTemplate.Company = mailTemplate.Company;
                    existingMailTemplate.Footer = mailTemplate.Footer;
                    existingMailTemplate.FromEmailAddress = mailTemplate.FromEmailAddress;
                    existingMailTemplate.Password = mailTemplate.Password;
                    existingMailTemplate.Subject = mailTemplate.Subject;
                    existingMailTemplate.Username = mailTemplate.Username;
                    existingMailTemplate.WebsiteUrl = mailTemplate.WebsiteUrl;

                    using (var context = new PropertyDBEntities())
                    {
                        context.Entry(existingMailTemplate).State = EntityState.Modified;

                        context.SaveChanges();
                    }

                    return true;
                }
                else
                {
                    return false;
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static bool Update(PropertyDetail propertyDetails, List<long> imageIDToRemove, List<byte[]> newImages)
        {
            try
            {
                PropertyDetail existingPropertyDetails = new PropertyDetail();
                using (var context = new PropertyDBEntities())
                {
                    existingPropertyDetails = context.PropertyDetails.Include("PropertyImages")
                                    .Where(t => t.PropertyID == propertyDetails.PropertyID)
                                    .FirstOrDefault();
                }

                if (existingPropertyDetails != null)
                {
                    existingPropertyDetails.Title = propertyDetails.Title;
                    existingPropertyDetails.Type = propertyDetails.Type;
                    existingPropertyDetails.NumberOfBedrooms = propertyDetails.NumberOfBedrooms;
                    existingPropertyDetails.Location = propertyDetails.Location;
                    existingPropertyDetails.Price = propertyDetails.Price;
                    existingPropertyDetails.Description = propertyDetails.Description;

                    using (var context = new PropertyDBEntities())
                    {
                        //Transaction block
                        using (var transaction = context.Database.BeginTransaction())
                        {
                            try
                            {
                                //Modifying just the property details
                                context.Entry(existingPropertyDetails).State = EntityState.Modified;
                                context.SaveChanges();

                                //Delete block for images that were removed from the property
                                IEnumerable<PropertyImage> existingImages = context.PropertyImages.Include("PropertyDetail")
                                                                .Where(t => imageIDToRemove.Contains(t.PropertyImageID))
                                                                .ToList();

                                if (existingImages != null && existingImages.ToList().Count != 0)
                                {
                                    context.PropertyImages.RemoveRange(existingImages);
                                    context.SaveChanges();
                                }

                                //Adding new images for the property
                                List<PropertyImage> newPropertyImages = new List<PropertyImage>();
                                foreach (byte[] newImage in newImages)
                                {
                                    PropertyImage newPropertyImage = new PropertyImage();
                                    newPropertyImage.PropertyID = propertyDetails.PropertyID;
                                    newPropertyImage.Image = newImage;

                                    newPropertyImages.Add(newPropertyImage);
                                }
                                if (newPropertyImages != null && newPropertyImages.Count != 0)
                                {
                                    context.PropertyImages.AddRange(newPropertyImages);
                                    context.SaveChanges();
                                }

                                //commit changes
                                transaction.Commit();
                            }
                            catch (Exception ex)
                            {
                                transaction.Rollback();
                                throw ex;
                            }
                        }

                    }
                    return true;
                }
                else
                {
                    return false;
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }