Example #1
0
        public HttpResponseMessage Get(HttpRequestMessage request)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;

                var Data = GenerateData.GenerateKey_Sys_Units();
                try
                {
                    foreach (Key_Sys_Unit key_sys_unit in Data)
                    {
                        Sys_Unit newsys_unit = new Sys_Unit();

                        newsys_unit.Website = key_sys_unit.Key.ToMD5() + ".netschool.vn";
                        newsys_unit.ParentUnitID = 40;
                        newsys_unit.Note = key_sys_unit.Encodedomain;
                        newsys_unit.CreatedDate = DateTime.Now;
                        newsys_unit.ModifiedDate = DateTime.Now;
                        newsys_unit.ModifiedBy = 1;
                        newsys_unit.CreatedBy = 1;
                        newsys_unit.Infor = "Generate Data";
                        //add sys_unit
                        _sys_unitsRepository.Add(newsys_unit);
                        _unitOfWork.Commit();
                        key_sys_unit.UnitID = newsys_unit.UnitID;
                        //add key_sys_unit
                        _key_sys_unitsRepository.Add(key_sys_unit);

                        WebSecurity.CreateUserAndAccount(key_sys_unit.Encodedomain, "12345678");

                        //Get UserByName
                        int UserId = WebSecurity.GetUserId(key_sys_unit.Encodedomain);
                        if (UserId > 0)
                        {
                            Sys_User newsys_user = new Sys_User();
                            newsys_user.DateOfBirth = DateTime.Now;
                            newsys_user.iType = key_sys_unit.UnitID;
                            newsys_user.CreatedDate = DateTime.Now;
                            newsys_user.ModifiedDate = DateTime.Now;
                            newsys_user.ModifiedBy = 1;
                            newsys_user.CreatedBy = 1;
                            newsys_user.Infor = "Generate Data";
                            newsys_user.Role = 7;
                            newsys_user.UserID = UserId.ToString();
                            newsys_user.UserName = key_sys_unit.Encodedomain;
                            newsys_user.LoginName = key_sys_unit.Encodedomain;
                            newsys_user.LastIPAddress = null;
                            newsys_user.LastLoginDate = DateTime.Now;
                            newsys_user.Year = DateTime.Now.AddYears(1);
                            _sys_userRepository.Add(newsys_user);
                        }
                        _unitOfWork.Commit();
                    }
                    response = request.CreateResponse(HttpStatusCode.OK, "Successful");
                }
                catch (Exception ex)
                {
                    response = request.CreateResponse(HttpStatusCode.ExpectationFailed, ex);
                }

                return response;
            }));
        }