Ejemplo n.º 1
0
        public Task UpdateLastWorkingDay(SocietyStaff societyStaff)
        {
            var taskResult = Task.Run(() =>
            {
                using (var context = new DbContext())
                {
                    var existingRecord = context
                                         .SocietyStaffList
                                         .Include(s => s.StaffType)
                                         .Include(s => s.Society)
                                         .FirstOrDefault(p => p.Id == societyStaff.Id);

                    if (existingRecord == null)
                    {
                        throw new Exception("Society Staff detail not found");
                    }
                    if (existingRecord.JoiningDate > societyStaff.LastWorkingDay)
                    {
                        throw new Exception("Last working day cannot be before date of joining");
                    }
                    if (societyStaff.Society != null)
                    {
                        societyStaff.SocietyId = societyStaff.Society.Id;
                        societyStaff.Society   = null;
                    }
                    existingRecord.LastWorkingDay = societyStaff.LastWorkingDay;

                    context.SaveChanges();
                }
            });

            return(taskResult);
        }
Ejemplo n.º 2
0
        public Task <SocietyStaff> Create(SocietyStaff societyStaff)
        {
            var taskResult = Task.Run(() =>
            {
                using (var context = new DbContext())
                {
                    var society = context
                                  .Societies
                                  .FirstOrDefault(s => s.Id == societyStaff.Society.Id);

                    if (society == null)
                    {
                        throw new Exception("Society not found");
                    }

                    if (societyStaff.JoiningDate < society.DateOfIncorporation)
                    {
                        throw new Exception("Joining date cannot be before date of incorporation of the society");
                    }

                    if (societyStaff.DateOfBirth.HasValue && societyStaff.JoiningDate < societyStaff.DateOfBirth.Value)
                    {
                        throw new Exception("Joining since date cannot be before Date of Birth");
                    }

                    if (societyStaff.StaffType != null)
                    {
                        societyStaff.StaffTypeId = societyStaff.StaffType.Id;
                        societyStaff.StaffType   = null;
                    }
                    if (societyStaff.Society != null)
                    {
                        societyStaff.SocietyId = societyStaff.Society.Id;
                        societyStaff.Society   = null;
                    }
                    context.SocietyStaffList.Add(societyStaff);
                    context.SaveChanges();

                    return(societyStaff);
                }
            });

            return(taskResult);
        }
 public Task UpdateLastWorkingDay(SocietyStaff societyStaff)
 {
     return(_societyStaffRepository.UpdateLastWorkingDay(societyStaff));
 }
 public Task Update(SocietyStaff societyStaff)
 {
     return(_societyStaffRepository.Update(societyStaff));
 }
 public Task <SocietyStaff> Create(SocietyStaff societyStaff)
 {
     return(_societyStaffRepository.Create(societyStaff));
 }
Ejemplo n.º 6
0
        public Task Update(SocietyStaff societyStaff)
        {
            var taskResult = Task.Run(() =>
            {
                using (var context = new DbContext())
                {
                    var existingRecord = context
                                         .SocietyStaffList
                                         .Include(s => s.StaffType)
                                         .Include(s => s.Society)
                                         .FirstOrDefault(p => p.Id == societyStaff.Id);

                    if (existingRecord == null)
                    {
                        throw new Exception("Society Staff detail not found");
                    }

                    var society = context
                                  .Societies
                                  .FirstOrDefault(s => s.Id == existingRecord.Society.Id);

                    if (society == null)
                    {
                        throw new Exception("Society not found");
                    }

                    if (societyStaff.JoiningDate < society.DateOfIncorporation)
                    {
                        throw new Exception("Joining date cannot be before date of incorporation of the society");
                    }

                    if (societyStaff.DateOfBirth.HasValue && societyStaff.JoiningDate < societyStaff.DateOfBirth.Value)
                    {
                        throw new Exception("Joining since date cannot be before Date of Birth");
                    }

                    if (societyStaff.StaffType != null)
                    {
                        societyStaff.StaffTypeId = societyStaff.StaffType.Id;
                        societyStaff.StaffType   = null;
                    }
                    if (societyStaff.Society != null)
                    {
                        societyStaff.SocietyId = societyStaff.Society.Id;
                        societyStaff.Society   = null;
                    }
                    existingRecord.Name          = societyStaff.Name;
                    existingRecord.PhoneNo       = societyStaff.PhoneNo;
                    existingRecord.AadharCardNo  = societyStaff.AadharCardNo;
                    existingRecord.Photo         = societyStaff.Photo;
                    existingRecord.DateOfBirth   = societyStaff.DateOfBirth;
                    existingRecord.Address       = societyStaff.Address;
                    existingRecord.NativeAddress = societyStaff.NativeAddress;
                    existingRecord.JoiningDate   = societyStaff.JoiningDate;

                    context.SaveChanges();
                }
            });

            return(taskResult);
        }