Esempio n. 1
0
        public ENT.UserProfile GetUserProfile(string id)
        {
            ENT.UserProfile lstEntity = new Entity.UserProfile();
            try
            {
                parFields.Clear();

                QueryDisctionery.SelectPart = "SELECT top 1 up_id,up_mobile,up_email,up_userid,up_address,up_userlevel,(case when up_userlevel=1 then 'Master Distributor' when up_userlevel=2 then 'Distributor' when up_userlevel=3 then 'Retailer' when up_userlevel=4 then 'ApiUser' else 'None' end) as UserLevelName,up_username,up_balance";
                QueryDisctionery.TablePart  = @"from UserProfile where up_userid='" + id + "'";

                using (SqlDataReader dr = objDBHelper.ExecuteReaderQuery(QueryDisctionery, parFields, objEntity))
                {
                    lstEntity = COM.DBHelper.CopyDataReaderToSingleEntity <ENT.UserProfile>(dr);
                    objDBHelper.Disposed();
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                parFields.Clear();
            }
            return(lstEntity);
        }
Esempio n. 2
0
        public ENT.UserProfile GetUserSlabName(Guid upperid)
        {
            ENT.UserProfile lstEntity = new Entity.UserProfile();
            try
            {
                parFields.Clear();

                QueryDisctionery.SelectPart = "SELECT top 1 slabid";
                QueryDisctionery.TablePart  = @"from UserProfile where up_userid='" + upperid + "'";

                using (SqlDataReader dr = objDBHelper.ExecuteReaderQuery(QueryDisctionery, parFields, objEntity))
                {
                    lstEntity = COM.DBHelper.CopyDataReaderToSingleEntity <ENT.UserProfile>(dr);
                    objDBHelper.Disposed();
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                parFields.Clear();
            }
            return(lstEntity);
        }
Esempio n. 3
0
        public Model.StaffInfo InsertUpdateStaff(Model.StaffInfo staffInfo)
        {
            try
            {
                var config = new MapperConfiguration(cfg => {
                    cfg.CreateMap <Model.StaffInfo, Entity.StaffInfo>();
                });
                IMapper mapper          = config.CreateMapper();
                var     staffInfoEntity = mapper.Map <Model.StaffInfo, Entity.StaffInfo>(staffInfo);

                if (staffInfoEntity.StaffInfoId == 0)
                {
                    Entity.UserProfile userProfile = new Entity.UserProfile
                    {
                        FirstName     = staffInfoEntity.FirstName,
                        LastName      = staffInfoEntity.LastName,
                        Email         = staffInfoEntity.Email,
                        Password      = Utilities.CreateRandomPassword(8),
                        ContactNumber = staffInfoEntity.MobileNumber,
                        RoleId        = (int)_schoolContext.Roles.Where(r => r.RoleName == "Staff").Select(s => s.RoleID).FirstOrDefault(),
                        UserId        = 0
                    };
                    _schoolContext.UserProfile.Add(userProfile);
                    _schoolContext.SaveChanges();
                    if (userProfile.UserId > 0)
                    {
                        staffInfoEntity.UserId   = userProfile.UserId;
                        staffInfoEntity.IsActive = true;
                        _schoolContext.StaffInfo.Add(staffInfoEntity);
                        _schoolContext.SaveChanges();
                        staffInfo.StaffInfoId = staffInfoEntity.StaffInfoId;
                        staffInfo.IsActive    = staffInfoEntity.IsActive;
                        staffInfo.UserId      = userProfile.UserId;
                    }
                }
                else
                {
                    _schoolContext.Entry(staffInfoEntity).State = EntityState.Modified;
                    _schoolContext.SaveChanges();
                }

                return(staffInfo);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Esempio n. 4
0
        public Model.SchoolBasicInfo InsertUpdatedSchool(Model.SchoolBasicInfo schoolBasicInfo)
        {
            try
            {
                var config = new MapperConfiguration(cfg => {
                    cfg.CreateMap <Model.SchoolBasicInfo, Entity.SchoolBasicInfo>();
                });
                IMapper mapper     = config.CreateMapper();
                var     schoolInfo = mapper.Map <Model.SchoolBasicInfo, Entity.SchoolBasicInfo>(schoolBasicInfo);
                if (schoolInfo.SchoolInfoId == 0)
                {
                    using (var dbContextTransaction = _schoolContext.Database.BeginTransaction())
                    {
                        try
                        {
                            Entity.UserProfile userProfile = new Entity.UserProfile
                            {
                                FirstName     = string.Empty,
                                LastName      = string.Empty,
                                Email         = schoolInfo.Email,
                                Password      = Utilities.CreateRandomPassword(8),
                                ContactNumber = schoolInfo.ContactNumber,
                                RoleId        = (int)_schoolContext.Roles.Where(r => r.RoleName == "SchoolAdmin").Select(s => s.RoleID).FirstOrDefault(),
                                UserId        = 0
                            };
                            _schoolContext.UserProfile.Add(userProfile);
                            _schoolContext.SaveChanges();
                            schoolInfo.IsActive = true;
                            _schoolContext.SchoolBasicInfo.Add(schoolInfo);
                            _schoolContext.SaveChanges();
                            if (userProfile.UserId > 0 && schoolInfo.SchoolInfoId > 0)
                            {
                                Entity.SchoolUserMapping schoolUserMapping = new Entity.SchoolUserMapping
                                {
                                    SchoolInfoId = schoolInfo.SchoolInfoId,
                                    UserId       = userProfile.UserId
                                };
                                _schoolContext.SchoolUserMapping.Add(schoolUserMapping);
                            }

                            _schoolContext.SaveChanges();
                            schoolBasicInfo.SchoolInfoId = schoolInfo.SchoolInfoId;
                            schoolBasicInfo.IsActive     = schoolInfo.IsActive;
                            schoolBasicInfo.UserId       = userProfile.UserId;

                            dbContextTransaction.Commit();
                        }
                        catch (Exception ex)
                        {
                            dbContextTransaction.Rollback();
                            throw ex;
                        }
                    }
                }
                else
                {
                    _schoolContext.Entry(schoolInfo).State = EntityState.Modified;
                    _schoolContext.SaveChanges();
                }


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