Ejemplo n.º 1
0
        private static async Task <BaseResponseData> CreateCompany()
        {
            CreateCompanyResult result = new CreateCompanyResult();

            if (User.bytes == null)
            {
                result.Result = GameEnum.WsResult.ParamsError;
                return(result);
            }
            var data = await InitHelpers.GetPse().DeserializeAsync <CreateCompanyReq>(User.bytes);

            if (data == null)
            {
                result.Result = GameEnum.WsResult.ParamsError;
                return(result);
            }
            var name = data.Name;
            var role = LogicServer.User.role;

            return(await CompanyController.Instance.CreateCompany(role.Id, name, result));
        }
Ejemplo n.º 2
0
        public async Task <CreateCompanyResult> CreateCompany(Guid roleId, string name, CreateCompanyResult result)
        {
            Company company = new Company(name);
            await CompanyDataHelper.Instance.SetCompanyByRoleIdAsync(roleId, company);

            result.DepartmentInfo = await DepartmentController.Instance.CreateDepartment();    //创建部门并初始化

            result.CompanyInfo.Id     = company.Id.ToString();
            result.CompanyInfo.Level  = company.Level;
            result.CompanyInfo.Name   = company.Name;
            result.CompanyInfo.CurExp = company.CurExp;

            result.CompanyInfo.CreateTime = company.CreateTime.Date.ToString();
            return(result);
        }
Ejemplo n.º 3
0
        public async Task <CreateCompanyResult> CreateCompany(IReliableStateManager sm, UserRole role, string name, CreateCompanyResult result)
        {
            if (string.IsNullOrEmpty(name))
            {
                result.Result = GameEnum.WsResult.ParamsError;
                return(result);
            }
            if (await CheckCompanyName(name))
            {
                result.Result = GameEnum.WsResult.DuplicationName;
                return(result);
            }
            if (await CheckCompanyExists(role.Id))
            {
                result.Result = GameEnum.WsResult.MoreCompany;
                return(result);
            }
            result = await CreateCompany(role.Id, name, result);

            return(result);
        }
Ejemplo n.º 4
0
        public CreateCompanyResult Create(string title, string shortDescription)
        {
            var result = new CreateCompanyResult();

            try
            {
                if (!_http.HttpContext.User.Identity.IsAuthenticated)
                {
                    return(new CreateCompanyResult(ResultType.Unauthorized));
                }

                var user = _userManager.GetUserAsync(_http.HttpContext.User).Result;

                if (!String.IsNullOrEmpty(title))
                {
                    result.Title = "OK";
                }
                else
                {
                    result.Title = "NO";
                }

                if (!String.IsNullOrEmpty(shortDescription))
                {
                    result.Description = "OK";
                }
                else
                {
                    result.Description = "NO";
                }

                if (user != null)
                {
                    result.Owner = "OK";
                }
                else
                {
                    result.Owner = "NO";
                }

                if (result.Title == "NO" || result.Description == "NO" || result.Owner == "NO")
                {
                    result.Error      = "Not all required fields were filled.";
                    result.StatusCode = 412;
                    return(result);
                }
                else
                {
                    result.StatusCode = 200;
                    var newCompany = new Company {
                        ShortDescription = shortDescription, Title = title, Owner = user
                    };
                    _context.Companies.Add(newCompany);
                    _context.CompanyTeam.Add(new CompanyTeam
                    {
                        RequestDate  = DateTime.Today,
                        ApprovalDate = DateTime.Today,
                        Approved     = true,
                        Comment      = "Init",
                        CompanyId    = newCompany.Id,
                        UserId       = user.Id
                    });
                    _context.SaveChanges();
                }

                return(result);
            }
            catch (Exception ex)
            {
                LogException(ex);
                return(new CreateCompanyResult(400, ex.Message));
            }
        }