示例#1
0
文件: Main.cs 项目: substans/TingTing
        public static void Main(string[] args)
        {
            RoomTest t = new RoomTest();

            t.Setup();
            t.BasicUsage();
            t.TearDown();
        }
        public override object Delete <T>(T entity)
        {
            BO.RoomTest roomtestBO = entity as BO.RoomTest;

            RoomTest roomtestDB = new RoomTest();

            roomtestDB.id = roomtestBO.ID;
            _dbSet.Remove(_context.RoomTests.Single <RoomTest>(p => p.id == roomtestBO.ID));
            _context.SaveChanges();

            var res = (BO.GbObject)(object) entity;

            return(roomtestDB);
        }
        public override object Save <T>(T entity)
        {
            BO.RoomTest roomtestBO = (BO.RoomTest)(object) entity;

            RoomTest roomtestDB = new RoomTest();

            #region RoomTest
            roomtestDB.id        = roomtestBO.ID;
            roomtestDB.Name      = roomtestBO.name;
            roomtestDB.ColorCode = roomtestBO.ColorCode;
            roomtestDB.IsDeleted = roomtestBO.IsDeleted.HasValue ? roomtestBO.IsDeleted : false;
            #endregion
            if (roomtestDB.id > 0)
            {
                //For Update Record

                //Find Schedule By ID
                RoomTest roomtest = _context.RoomTests.Where(p => p.id == roomtestDB.id && (p.IsDeleted == false || p.IsDeleted == null)).FirstOrDefault <RoomTest>();

                if (roomtest != null)
                {
                    #region Location
                    roomtest.id             = roomtestBO.ID;
                    roomtest.Name           = roomtestBO.name == null ? roomtest.Name : roomtestBO.name;
                    roomtest.ColorCode      = roomtestBO.ColorCode;
                    roomtest.IsDeleted      = roomtestBO.IsDeleted == null ? roomtestBO.IsDeleted : roomtest.IsDeleted;
                    roomtest.UpdateDate     = roomtestBO.UpdateDate;
                    roomtest.UpdateByUserID = roomtestBO.UpdateByUserID;
                    #endregion
                    _context.Entry(roomtest).State = System.Data.Entity.EntityState.Modified;
                }
                else
                {
                    return new BO.ErrorObject {
                               errorObject = "", ErrorMessage = "Please pass valid roomtest details.", ErrorLevel = ErrorLevel.Error
                    }
                };
            }
            else
            {
                roomtestDB.CreateDate     = roomtestBO.CreateDate;
                roomtestDB.CreateByUserID = roomtestBO.CreateByUserID;
                _dbSet.Add(roomtestDB);
            }
            _context.SaveChanges();

            var res = Convert <BO.RoomTest, RoomTest>(roomtestDB);
            return((object)res);
        }
        public override T Convert <T, U>(U entity)
        {
            RoomTest roomtest = entity as RoomTest;

            if (roomtest == null)
            {
                return(default(T));
            }

            BO.RoomTest roomtestBO = new BO.RoomTest();
            roomtestBO.name      = roomtest.Name;
            roomtestBO.ID        = roomtest.id;
            roomtestBO.ColorCode = roomtest.ColorCode;

            if (roomtest.IsDeleted.HasValue)
            {
                roomtestBO.IsDeleted = roomtest.IsDeleted.Value;
            }
            if (roomtest.UpdateByUserID.HasValue)
            {
                roomtestBO.UpdateByUserID = roomtest.UpdateByUserID.Value;
            }

            List <BO.Room> lstRooms = new List <BO.Room>();

            foreach (var item in roomtest.Rooms)
            {
                using (RoomRepository sr = new RoomRepository(_context))
                {
                    lstRooms.Add(sr.ObjectConvert <BO.Room, Room>(item));
                }
            }
            roomtestBO.rooms = lstRooms;

            return((T)(object)roomtestBO);
        }
示例#5
0
 public HttpResponseMessage IsUnique([FromBody] RoomTest User)
 {
     return(requestHandler.ValidateUniqueName(Request, User));
 }
示例#6
0
 public HttpResponseMessage Delete([FromBody] RoomTest User)
 {
     return(requestHandler.DeleteGbObject(Request, User));
 }
示例#7
0
 public HttpResponseMessage Post([FromBody] RoomTest data)
 {
     return(requestHandler.CreateGbObject(Request, data));
 }
示例#8
0
 public HttpResponseMessage Get([FromBody] RoomTest data)
 {
     return(requestHandler.GetGbObjects(Request, data));
 }
示例#9
0
        public override object Save <T>(T entity)
        {
            BO.Room roomBO = (BO.Room)(object) entity;

            Room     roomDB     = new Room();
            RoomTest roomtestDB = new RoomTest();

            #region room
            roomDB.id   = roomBO.ID;
            roomDB.Name = roomBO.name;
            roomDB.ContactPersonName = roomBO.contactersonName;
            roomDB.Phone             = roomBO.phone;
            roomDB.IsDeleted         = roomBO.IsDeleted.HasValue ? roomBO.IsDeleted : false;
            #endregion

            #region Room Test
            roomtestDB.id = roomBO.roomTest.ID;
            //roomtestDB.Name = roomBO.roomTest.name;
            //roomtestDB.IsDeleted = roomBO.roomTest.IsDeleted.HasValue ? roomBO.roomTest.IsDeleted : false;
            #endregion

            if (roomBO.roomTest.ID > 0)
            {
                RoomTest roomtest = _context.RoomTests.Where(p => p.id == roomBO.roomTest.ID && (p.IsDeleted == false || p.IsDeleted == null)).FirstOrDefault <RoomTest>();
                if (roomtest != null)
                {
                    _context.Entry(roomtest).State = System.Data.Entity.EntityState.Modified;
                    roomtestDB = roomtest;
                }
                else
                {
                    return new BO.ErrorObject {
                               errorObject = "", ErrorMessage = "Please pass valid roomtest detail.", ErrorLevel = ErrorLevel.Error
                    }
                };
            }
            if (roomBO.location.ID > 0)
            {
                Location location = _context.Locations.Where(p => p.id == roomBO.location.ID && (p.IsDeleted == false || p.IsDeleted == null)).FirstOrDefault <Location>();
                if (location != null)
                {
                    _context.Entry(location).State = System.Data.Entity.EntityState.Modified;

                    roomDB.Location = location;
                }
                else
                {
                    return new BO.ErrorObject {
                               errorObject = "", ErrorMessage = "Please pass valid location detail.", ErrorLevel = ErrorLevel.Error
                    }
                };
            }
            roomDB.RoomTest = roomtestDB;

            if (roomBO.schedule != null)
            {
                #region Schedule
                if (roomBO.schedule != null)
                {
                    if (roomBO.schedule.ID > 0)
                    {
                        Schedule schedule = _context.Schedules.Where(p => p.id == roomBO.schedule.ID).FirstOrDefault <Schedule>();
                        if (schedule != null)
                        {
                            roomDB.Schedule = schedule;
                        }
                        else
                        {
                            return new BO.ErrorObject {
                                       errorObject = "", ErrorMessage = "Please pass valid Schedule.", ErrorLevel = ErrorLevel.Error
                            }
                        };
                    }
                }
                #endregion
            }
            else
            {
                //Default schedule
                Schedule defaultschedule = _context.Schedules.Where(p => p.IsDefault == true).FirstOrDefault <Schedule>();
                if (defaultschedule != null)
                {
                    roomDB.Schedule = defaultschedule;
                }
                else
                {
                    return new BO.ErrorObject {
                               errorObject = "", ErrorMessage = "Please set default schedule in database.", ErrorLevel = ErrorLevel.Error
                    }
                };
            }


            if (roomDB.id > 0)
            {
                if (_context.Rooms.Any(o => o.Name == roomBO.name && o.LocationID == roomBO.location.ID && o.id != roomDB.id && (o.IsDeleted == false || o.IsDeleted == null)))
                {
                    return(new BO.ErrorObject {
                        ErrorMessage = "Room already exists for selected location and test.", errorObject = "", ErrorLevel = ErrorLevel.Error
                    });
                }
                //For Update Record

                //Find Room By ID
                Room room = _context.Rooms.Where(p => p.id == roomDB.id && (p.IsDeleted == false || p.IsDeleted == null)).FirstOrDefault <Room>();

                if (room != null)
                {
                    #region Location
                    room.id   = roomBO.ID;
                    room.Name = roomBO.name == null ? room.Name : roomBO.name;
                    room.ContactPersonName = roomBO.contactersonName == null ? room.ContactPersonName : roomBO.contactersonName;
                    room.Phone             = roomBO.phone == null ? room.Phone : roomBO.phone;
                    room.IsDeleted         = roomBO.IsDeleted.HasValue ? roomBO.IsDeleted : room.IsDeleted;
                    room.UpdateDate        = roomBO.UpdateDate;
                    room.UpdateByUserID    = roomBO.UpdateByUserID;
                    #endregion

                    #region RoomTest
                    if (roomBO.roomTest != null)
                    {
                        if (roomBO.roomTest.ID > 0)
                        {
                            RoomTest roomtest = _context.RoomTests.Where(p => p.id == roomBO.roomTest.ID).FirstOrDefault <RoomTest>();

                            if (roomtest != null)
                            {
                                room.RoomTest = roomtest;
                            }
                            else
                            {
                                return new BO.ErrorObject {
                                           errorObject = "", ErrorMessage = "Please pass valid roomtest detail.", ErrorLevel = ErrorLevel.Error
                                }
                            };
                        }
                    }
                    #endregion

                    if (roomBO.location.ID > 0)
                    {
                        Location location = _context.Locations.Where(p => p.id == roomBO.location.ID && (p.IsDeleted == false || p.IsDeleted == null)).FirstOrDefault <Location>();
                        if (location != null)
                        {
                            _context.Entry(location).State = System.Data.Entity.EntityState.Modified;
                            room.Location = location;
                        }
                        else
                        {
                            return new BO.ErrorObject {
                                       errorObject = "", ErrorMessage = "Please pass valid location detail.", ErrorLevel = ErrorLevel.Error
                            }
                        };
                    }

                    #region Schedule
                    if (roomBO.schedule != null)
                    {
                        if (roomBO.schedule.ID > 0)
                        {
                            Schedule schedule = _context.Schedules.Where(p => p.id == roomBO.schedule.ID).FirstOrDefault <Schedule>();

                            if (schedule != null)
                            {
                                room.Schedule = schedule;
                            }
                            else
                            {
                                return new BO.ErrorObject {
                                           errorObject = "", ErrorMessage = "Please pass valid Schedule.", ErrorLevel = ErrorLevel.Error
                                }
                            };
                        }
                    }
                    #endregion

                    _context.Entry(room).State = System.Data.Entity.EntityState.Modified;
                }
                else
                {
                    return new BO.ErrorObject {
                               errorObject = "", ErrorMessage = "Please pass valid room details.", ErrorLevel = ErrorLevel.Error
                    }
                };
            }
            else
            {
                if (_context.Rooms.Any(o => o.Name == roomBO.name && o.LocationID == roomBO.location.ID && (o.IsDeleted.HasValue == false || (o.IsDeleted.HasValue == true && o.IsDeleted.Value == false))))
                {
                    return(new BO.ErrorObject {
                        ErrorMessage = "Room already exists for selected location and test.", errorObject = "", ErrorLevel = ErrorLevel.Error
                    });
                }

                roomDB.CreateDate     = roomBO.CreateDate;
                roomDB.CreateByUserID = roomBO.CreateByUserID;
                _dbSet.Add(roomDB);
            }
            _context.SaveChanges();

            var res = Convert <BO.Room, Room>(roomDB);
            return((object)res);
        }
示例#10
0
        public override object Save <T>(T entity)
        {
            BO.Doctor                    doctorBO                 = (BO.Doctor)(object) entity;
            BO.ErrorObject               errObj                   = new BO.ErrorObject();
            BO.User                      userBO                   = new BO.User();
            Doctor                       doctorDB                 = new Doctor();
            User                         userDB                   = new User();
            List <DoctorSpeciality>      lstDoctorSpecility       = new List <DoctorSpeciality>();
            List <DoctorRoomTestMapping> lstDoctorRoomTestMapping = new List <DoctorRoomTestMapping>();

            doctorDB.Id = doctorBO.ID;

            using (var dbContextTransaction = _context.Database.BeginTransaction())
            {
                ////Find Record By ID
                User user_ = _context.Users.Include("UserCompanyRoles").Include("AddressInfo").Include("ContactInfo").Where(p => p.id == doctorBO.user.ID).FirstOrDefault <User>();
                if (user_ != null)
                {
                    BO.AddUser updUserBO = new BO.AddUser();
                    updUserBO.user                        = doctorBO.user;
                    updUserBO.user.UserName               = string.IsNullOrEmpty(user_.UserName) ? user_.UserName : doctorBO.user.UserName;
                    updUserBO.user.FirstName              = string.IsNullOrEmpty(user_.FirstName) ? user_.FirstName : doctorBO.user.FirstName;
                    updUserBO.user.LastName               = string.IsNullOrEmpty(user_.LastName) ? user_.LastName : doctorBO.user.LastName;
                    updUserBO.user.MiddleName             = string.IsNullOrEmpty(user_.MiddleName) ? user_.MiddleName: doctorBO.user.MiddleName;
                    updUserBO.user.Gender                 = doctorBO.user.Gender;
                    updUserBO.user.UserType               = !Enum.IsDefined(typeof(BO.GBEnums.UserType), doctorBO.user.UserType) ? (BO.GBEnums.UserType)user_.UserType : doctorBO.user.UserType;
                    updUserBO.user.ImageLink              = string.IsNullOrEmpty(doctorBO.user.ImageLink) ? user_.ImageLink : doctorBO.user.ImageLink;
                    updUserBO.user.C2FactAuthEmailEnabled = doctorBO.user.C2FactAuthEmailEnabled == true || doctorBO.user.C2FactAuthEmailEnabled == false ? doctorBO.user.C2FactAuthEmailEnabled : (bool)user_.C2FactAuthEmailEnabled;
                    updUserBO.user.C2FactAuthEmailEnabled = doctorBO.user.C2FactAuthSMSEnabled == true || doctorBO.user.C2FactAuthSMSEnabled == false ? doctorBO.user.C2FactAuthSMSEnabled : (bool)user_.C2FactAuthSMSEnabled;
                    updUserBO.user.ID                     = doctorBO.user.ID;
                    updUserBO.user.Roles                  = doctorBO.user.Roles;
                    updUserBO.company                     = doctorBO.user.UserCompanies.ToList().Select(p => p.Company).FirstOrDefault();
                    updUserBO.role                        = doctorBO.user.Roles.ToArray();
                    // if (doctorBO.DoctorSpecialities.Count > 0) updUserBO.DoctorSpecialities = doctorBO.user.DoctorSpecialities;
                    if (doctorBO.user.AddressInfo != null && doctorBO.user.AddressInfo.ID > 0)
                    {
                        updUserBO.address = doctorBO.user.AddressInfo;
                    }
                    if (doctorBO.user.ContactInfo != null && doctorBO.user.ContactInfo.ID > 0)
                    {
                        updUserBO.contactInfo = doctorBO.user.ContactInfo;
                    }
                    using (UserRepository userRepo = new UserRepository(_context))
                    {
                        object obj = userRepo.Save <BO.AddUser>(updUserBO);
                        if (obj.GetType() == errObj.GetType())
                        {
                            errObj = (BO.ErrorObject)obj;
                            dbContextTransaction.Rollback();
                            return(new BO.ErrorObject {
                                ErrorMessage = errObj.ErrorMessage, errorObject = "", ErrorLevel = ErrorLevel.Error
                            });
                        }
                        else
                        {
                            userBO = (BO.User)obj;
                        }
                        doctorDB.User = _context.Users.Include("UserCompanyRoles").Include("UserCompanies").Where(p => p.id == doctorBO.user.ID).FirstOrDefault <User>();
                    }
                    //_context.Entry(user_).State = System.Data.Entity.EntityState.Modified;
                }
                else
                {
                    BO.AddUser addUserBO = new BO.AddUser();
                    addUserBO.user = doctorBO.user;
                    // addUserBO.user.DoctorSpecialities = doctorBO.DoctorSpecialities;
                    addUserBO.user.Roles  = doctorBO.user.Roles;
                    addUserBO.company     = doctorBO.user.UserCompanies.ToList().Select(p => p.Company).FirstOrDefault();
                    addUserBO.role        = doctorBO.user.Roles.ToArray();
                    addUserBO.address     = doctorBO.user.AddressInfo;
                    addUserBO.contactInfo = doctorBO.user.ContactInfo;
                    using (UserRepository userRepo = new UserRepository(_context))
                    {
                        object obj = userRepo.Save <BO.AddUser>(addUserBO);
                        if (obj.GetType() == errObj.GetType())
                        {
                            errObj = (BO.ErrorObject)obj;
                            dbContextTransaction.Rollback();
                            return(new BO.ErrorObject {
                                ErrorMessage = errObj.ErrorMessage, errorObject = "", ErrorLevel = ErrorLevel.Error
                            });
                        }
                        else
                        {
                            userBO = (BO.User)obj;
                        }
                        doctorBO.user.ID = userBO.ID;
                        doctorDB.User    = _context.Users.Include("UserCompanyRoles").Include("UserCompanies").Where(p => p.id == doctorBO.user.ID && p.UserCompanyRoles.Any(x => x.RoleID == (int)BO.GBEnums.RoleType.Doctor)).FirstOrDefault <User>();
                    }
                }

                if (doctorBO.DoctorSpecialities.Count > 0)
                {
                    _dbSetDocSpecility.RemoveRange(_context.DoctorSpecialities.Where(c => c.DoctorID == doctorBO.user.ID));
                    _context.SaveChanges();
                    Specialty        specilityDB       = null;
                    DoctorSpeciality doctorSpecilityDB = null;
                    foreach (var item in doctorBO.DoctorSpecialities)
                    {
                        BO.DoctorSpeciality doctorSpecialityBO = (BO.DoctorSpeciality)(object) item;
                        specilityDB                 = new Specialty();
                        doctorSpecilityDB           = new DoctorSpeciality();
                        doctorSpecilityDB.IsDeleted = doctorSpecialityBO.IsDeleted.HasValue ? doctorSpecialityBO.IsDeleted.Value : false;
                        doctorSpecilityDB.Doctor    = doctorDB;
                        //Find Record By ID
                        Specialty speclity = _context.Specialties.Where(p => p.id == doctorSpecialityBO.ID).FirstOrDefault <Specialty>();
                        if (speclity == null)
                        {
                            dbContextTransaction.Rollback();
                            return(new BO.ErrorObject {
                                ErrorMessage = "Invalid specility " + item.ToString() + " details.", errorObject = "", ErrorLevel = ErrorLevel.Error
                            });
                        }
                        if (!lstDoctorSpecility.Select(p => p.Specialty).Contains(speclity))
                        {
                            doctorSpecilityDB.Specialty    = speclity;
                            _context.Entry(speclity).State = System.Data.Entity.EntityState.Modified;
                            lstDoctorSpecility.Add(doctorSpecilityDB);
                        }
                        ;
                    }
                }
                doctorDB.DoctorSpecialities = lstDoctorSpecility;

                if (doctorBO.DoctorRoomTestMappings != null)
                {
                    if (doctorBO.DoctorRoomTestMappings.Count > 0)
                    {
                        _dbSetDocRoomTestMapping.RemoveRange(_context.DoctorRoomTestMappings.Where(c => c.DoctorId == doctorBO.user.ID));
                        _context.SaveChanges();
                        RoomTest roomTestDB = null;
                        DoctorRoomTestMapping doctorRoomTestMappingDB = null;
                        foreach (var item in doctorBO.DoctorRoomTestMappings)
                        {
                            BO.DoctorRoomTestMapping doctorRoomTestMappingBO = (BO.DoctorRoomTestMapping)(object) item;
                            roomTestDB = new RoomTest();
                            doctorRoomTestMappingDB           = new DoctorRoomTestMapping();
                            doctorRoomTestMappingDB.IsDeleted = doctorRoomTestMappingBO.IsDeleted.HasValue ? doctorRoomTestMappingBO.IsDeleted.Value : false;
                            doctorRoomTestMappingDB.Doctor    = doctorDB;
                            //Find Record By ID
                            RoomTest roomTest = _context.RoomTests.Where(p => p.id == doctorRoomTestMappingBO.ID).FirstOrDefault <RoomTest>();
                            if (roomTest == null)
                            {
                                dbContextTransaction.Rollback();
                                return(new BO.ErrorObject {
                                    ErrorMessage = "Invalid specility " + item.ToString() + " details.", errorObject = "", ErrorLevel = ErrorLevel.Error
                                });
                            }
                            if (!lstDoctorRoomTestMapping.Select(p => p.RoomTest).Contains(roomTest))
                            {
                                doctorRoomTestMappingDB.RoomTest = roomTest;
                                _context.Entry(roomTest).State   = System.Data.Entity.EntityState.Modified;
                                lstDoctorRoomTestMapping.Add(doctorRoomTestMappingDB);
                            }
                            ;
                        }
                    }
                    doctorDB.DoctorRoomTestMappings = lstDoctorRoomTestMapping;
                }

                if (doctorDB.Id > 0)
                {
                    //Find Doctor By ID
                    Doctor doctor = _context.Doctors.Where(p => p.Id == doctorBO.user.ID && (p.IsDeleted.HasValue == false || (p.IsDeleted.HasValue == true && p.IsDeleted.Value == false))).FirstOrDefault <Doctor>();

                    if (doctor == null)
                    {
                        doctorDB = new Doctor();
                    }
                    #region Doctor
                    doctorDB.Id               = doctorBO.ID;
                    doctorDB.LicenseNumber    = string.IsNullOrEmpty(doctorBO.LicenseNumber) ? doctor.LicenseNumber : doctorBO.LicenseNumber;
                    doctorDB.WCBAuthorization = string.IsNullOrEmpty(doctorBO.WCBAuthorization) ? doctor.WCBAuthorization : doctorBO.WCBAuthorization;
                    doctorDB.WcbRatingCode    = string.IsNullOrEmpty(doctorBO.WcbRatingCode) ? doctor.WcbRatingCode : doctorBO.WcbRatingCode;
                    doctorDB.NPI              = string.IsNullOrEmpty(doctorBO.NPI) ? doctor.NPI : doctorBO.NPI;
                    doctorDB.Title            = string.IsNullOrEmpty(doctorBO.Title) ? doctor.Title : doctorBO.Title;
                    doctorDB.TaxTypeId        = !Enum.IsDefined(typeof(BO.GBEnums.TaxType), doctorBO.TaxType) ? System.Convert.ToByte((BO.GBEnums.TaxType)doctor.TaxTypeId) : System.Convert.ToByte(doctorBO.TaxType);
                    doctorDB.IsDeleted        = doctorBO.IsDeleted.HasValue ? doctorBO.IsDeleted : (doctorBO.IsDeleted.HasValue ? doctor.IsDeleted : false);
                    doctorDB.UpdateDate       = doctorBO.UpdateDate;
                    doctorDB.UpdateByUserID   = doctorBO.UpdateByUserID;
                    doctorDB.IsCalendarPublic = doctorBO.IsCalendarPublic;
                    #endregion
                    // doctorDB = doctor;
                    // _context.Entry(doctorDB).State = System.Data.Entity.EntityState.Modified;
                    doctorDB = _context.Doctors.Add(doctorDB);

                    //else
                    //{
                    //    dbContextTransaction.Rollback();
                    //    return new BO.ErrorObject { ErrorMessage = "Please pass valid doctor details.", errorObject = "", ErrorLevel = ErrorLevel.Error };
                    //}
                }
                else
                {
                    doctorDB.LicenseNumber    = doctorBO.LicenseNumber;
                    doctorDB.WCBAuthorization = doctorBO.WCBAuthorization;
                    doctorDB.WcbRatingCode    = doctorBO.WcbRatingCode;
                    doctorDB.NPI              = doctorBO.NPI;
                    doctorDB.Title            = doctorBO.Title;
                    doctorDB.TaxTypeId        = System.Convert.ToByte(doctorBO.TaxType);
                    doctorDB.IsDeleted        = doctorBO.IsDeleted.HasValue ? doctorBO.IsDeleted : false;
                    doctorDB.UpdateDate       = doctorBO.UpdateDate;
                    doctorDB.UpdateByUserID   = doctorBO.UpdateByUserID;
                    doctorDB.CreateDate       = doctorBO.CreateDate;
                    doctorDB.CreateByUserID   = doctorBO.CreateByUserID;
                    doctorDB.IsCalendarPublic = doctorBO.IsCalendarPublic;

                    _dbSet.Add(doctorDB);
                }
                _context.SaveChanges();
                dbContextTransaction.Commit();
            }
            var res = Convert <BO.Doctor, Doctor>(doctorDB);
            return((object)res);
        }