public void DeleteAddress(int studentId)
        {
            Contract.Requires<ArgumentOutOfRangeException>(studentId > 0, "The studentId must be > 0!");

            using (var context = new SchoolContext())
            {
                var addressToBeDeleted = new Address()
                {
                    StudentId = studentId
                };

                try
                {
                    context.Addresses.Attach(addressToBeDeleted);
                    context.Addresses.Remove(addressToBeDeleted);

                    if (context.SaveChanges() != 0)
                    {
                        /*
                        Logger.Write("The address " + addressToBeDeleted + " was successfully removed!", "General", 2, 2, TraceEventType.Information);
                         * */
                    }/*
                    else
                    {
                        Logger.Write("The address " + addressToBeDeleted + " was not removed!", "Important", 1, 1, TraceEventType.Error);
                    }*/
                }
                catch
                {
                    throw new NoSuchEntityException("The semester with the id=" + addressToBeDeleted + " does not exist in the database");
                }

            }
        }
        public virtual Student GetStudentForCourses(IStudentMock userMock)
        {
            int noProducts = userMock.GetNumberOfCoursesForStuent();

            if (noProducts >= 0)
            {
                var student = new Student
                {
                    FirstName = "reqwe",
                    LastName = "gfsfgfdfds",
                    CNP = "1234567891234",
                    SID = 123,
                    EnrollmentDate = DateTime.Now,
                    Emails = new[] { new Email("*****@*****.**"), }
                };

                var address = new Address
                {
                    City = "New York",
                    Country = "USA",
                    State = "NYQ",
                    PostalCode = "12345",
                    Street = "Brooklyn 33",
                    Student = student
                };

                return student;
            }
            return null;
        }
        public void DeleteAddress(Address address)
        {
            Contract.Requires<ArgumentNullException>(address != null, "The address must be non-null!");

            using (var context = new SchoolContext())
            {
                try
                {
                    context.Addresses.Attach(address);
                    context.Addresses.Remove(address);

                    if (context.SaveChanges() != 0)
                    {
                        /*
                        Logger.Write("The address " + address + " was successfully removed!", "General", 2, 2, TraceEventType.Information);
                         */
                    }/*
                    else
                    {
                        Logger.Write("The address " + address + " was not removed!", "Important", 1, 1, TraceEventType.Error);
                    }*/
                }
                catch
                {
                    throw new NoSuchEntityException("The semester with the id=" + address + " does not exist in the database");
                }
            }
        }
 public void ValidateStudentIsPresent(Address address, ValidationResults results)
 {
     if (address.StudentId == 0 && address.Student == null)
     {
         results.AddResult(new Microsoft.Practices.EnterpriseLibrary.Validation.ValidationResult
             (
             "The address must have a student", results, "ValidationMethod", "error", null)
             );
     }
 }
Example #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Employer" /> class.
 /// </summary>
 /// <param name="_name">           The _name. </param>
 /// <param name="_startDate">      The _start date. </param>
 /// <param name="_endDate">        The _end date. </param>
 /// <param name="_address">        The _address. </param>
 /// <param name="_supName">        Name of the _sup. </param>
 /// <param name="_phoneNumber">    The _phone number. </param>
 /// <param name="_position">       The _position. </param>
 /// <param name="_startingSalary"> The _starting salary. </param>
 /// <param name="_endingSalary">   The _ending salary. </param>
 /// <param name="_leaving">        The _leaving. </param>
 /// <param name="_respon">         The _respon. </param>
 public Employer(String _name, DateTime _startDate, DateTime? _endDate, Address _address, String _supName,
     String _phoneNumber, String _position, Decimal _startingSalary, Decimal _endingSalary, String _leaving,
     String _respon)
     : this()
 {
     Name = _name;
     StartDate = _startDate;
     if (_endDate != null)
     {
         EndDate = _endDate;
     }
     EmployerAddress = _address;
     SupervisorName = _supName;
     PhoneNumber = _phoneNumber;
     Position = _position;
     StartingSalary = _startingSalary;
     EndingSalary = _endingSalary;
     ReasonForLeaving = _leaving;
     Responsibilities = _respon;
 }
        public void AddAddress(Address address)
        {
            using (var context = new SchoolContext())
            {
                context.Addresses.Add(address);

                if (context.SaveChanges() != 0)
                {
                    /*
                    if (Logger.IsLoggingEnabled())
                    {
                        Logger.Write("The address: " + address + " has been successfully added!", "General", 2, 2, TraceEventType.Information);
                    }*/
                }
                /*else
                {
                    if (Logger.IsLoggingEnabled())
                    {
                        Logger.Write("The address: " + address + " insertion has failed!", "Important", 1, 1, TraceEventType.Error);
                    }
                }*/
            }
        }
        public Address UpdateAddress(int studentId, Address address)
        {
            Contract.Requires<ArgumentOutOfRangeException>(studentId > 0, "The studentId must be > 0!");
            Contract.Requires<ArgumentNullException>(address != null, "The address must be non-null!");

            using (var context = new SchoolContext())
            {
                var addressToBeUpdated = context.Addresses.SingleOrDefault(a => a.StudentId == studentId);

                if (addressToBeUpdated != null)
                {
                    addressToBeUpdated.Street = address.Street;
                    addressToBeUpdated.City = address.City;
                    addressToBeUpdated.State = address.State;
                    addressToBeUpdated.Country = address.Country;
                    addressToBeUpdated.PostalCode = address.PostalCode;

                    if (context.SaveChanges() != 0)
                    {
                        /*
                        Logger.Write("The address " + addressToBeUpdated + " was successfully updated!", "General", 2, 2, TraceEventType.Information);
                         */
                    }/*
                    else
                    {
                        Logger.Write("The address " + addressToBeUpdated + " was not updated!", "Important", 1, 1, TraceEventType.Error);
                    }*/

                    return addressToBeUpdated;
                }
                else
                {
                    Logger.Write("The address with id: " + studentId + " doesn't exist in the database!", "Important", 1, 1, TraceEventType.Error);
                    throw new NoSuchEntityException("The address with id: " + studentId +
                                                    " doesn't exist in the database!");
                }
            }
        }
 public void Dispose()
 {
     _item.EntityFacts.EntityPropertyChanged -= ItemPropertyChanged;
     _item = null;
 }
 public StaffingResourceAddressItemViewModel(Address item)
 {
     Debug.Assert(item != null);
     Item = item;
 }
 // Update
 public Address UpdateAddress(int studentId, Address student)
 {
     return DataMapperFactory.GetMapperFactory().AddressMapper.UpdateAddress(studentId, student);
 }
 public void DeleteAddress(Address student)
 {
     DataMapperFactory.GetMapperFactory().AddressMapper.DeleteAddress(student);
 }
 public void DeleteAddress(Address address)
 {
     address.EntityFacts.EntityAspect.Delete();
 }