Example #1
0
        public IHttpActionResult CreateSuperAdmin([FromBody] SuperAdminModel.Format_Create SuperAdmin)
        {
            string logForm = "Form : " + JsonConvert.SerializeObject(SuperAdmin);
            string logAPI  = "[Post] " + Request.RequestUri.ToString();

            if (!ModelState.IsValid || SuperAdmin == null)
            {
                Global._appLogger.Warn(logAPI + " || Input Parameter not expected || " + logForm);
                return(Content(HttpStatusCode.BadRequest, HttpResponseFormat.InvaildData()));
            }

            try
            {
                SuperAdminModel model = new SuperAdminModel();
                int             id    = model.Create(SuperAdmin);
                return(Content(HttpStatusCode.OK, HttpResponseFormat.Success(id)));
            }
            catch (CDSException cdsEx)
            {
                return(Content(HttpStatusCode.BadRequest, CDSException.GetCDSErrorMessageByCode(cdsEx.ErrorId)));
            }
            catch (Exception ex)
            {
                StringBuilder logMessage = LogHelper.BuildExceptionMessage(ex);
                logMessage.AppendLine(logForm);
                Global._appLogger.Error(logAPI + logMessage);

                return(Content(HttpStatusCode.InternalServerError, ex));
            }
        }
Example #2
0
        public SuperAdminModel AddSuperAdmin(AddAdminDto dto)
        {
            return(ProtectedExecute <AddAdminDto, SuperAdminModel>(adminDto =>
            {
                CheckActiveSuperAdmin(adminDto.SuperAdminSession);

                if (AccountRepo.Get(adminDto.AccountId.GetValueOrDefault()) == null)
                {
                    throw new NotFoundException("Account");
                }

                if (IsSuperAdmin(adminDto.AccountId.GetValueOrDefault()))
                {
                    throw new ConflictException("super-admin account");
                }

                AdminModel admin = AdminRepo.GetByAccountId(adminDto.AccountId.GetValueOrDefault());

                if (admin == null)
                {
                    AdminModel adminModel = Mapper.Map <AddAdminDto, AdminModel>(adminDto);
                    admin = AdminRepo.Create(adminModel);
                }

                SuperAdminModel model = Mapper.Map <AdminModel, SuperAdminModel>(admin);
                return SuperAdminRepo.Create(model);
            }, dto));
        }
Example #3
0
        private AuthenticationProperties CustomizeAuthenticationProperties(string username, string clientId)
        {
            switch (clientId)
            {
            case APIServiceClient.Admin:
            {
                EmployeeModel model    = new EmployeeModel();
                var           employee = model.GetByEmail(username);

                if (employee != null)
                {
                    var employeeTokenInfo = new AuthenticationProperties(new Dictionary <string, string>
                        {
                            { "Id", employee.Id.ToString() },
                            { "EmployeeNumber", (employee.EmployeeNumber != null) ? employee.EmployeeNumber : "" },
                            { "FirstName", (employee.FirstName != null) ? employee.FirstName.ToString() : "" },
                            { "LastName", (employee.LastName != null) ? employee.LastName.ToString() : "" },
                            { "Email", employee.Email },
                            { "PhotoURL", (employee.PhotoURL != null) ? employee.PhotoURL.ToString() : "" },
                            { "Lang", (employee.Lang != null) ? employee.Lang.ToString() : "" },
                            { "AdminFlag", employee.AdminFlag.ToString() },
                            { "Client_Id", APIServiceClient.Admin }
                        });

                    return(employeeTokenInfo);
                }
            }
            break;

            case APIServiceClient.SuperAdmin:
            {
                SuperAdminModel model      = new SuperAdminModel();
                var             superAdmin = model.GetByEmail(username);

                if (superAdmin != null)
                {
                    var superAdminTokenInfo = new AuthenticationProperties(new Dictionary <string, string>
                        {
                            { "Id", superAdmin.Id.ToString() },
                            { "FirstName", (superAdmin.FirstName != null) ? superAdmin.FirstName.ToString() : "" },
                            { "LastName", (superAdmin.LastName != null) ? superAdmin.LastName.ToString() : "" },
                            { "Email", superAdmin.Email },
                            { "Client_Id", APIServiceClient.SuperAdmin }
                        });
                    return(superAdminTokenInfo);
                }
            }
            break;
            }
            return(null);
        }
Example #4
0
 public bool Put(string id, SuperAdminModel superAdmin)
 {
     try {
         var client  = new RestClient();
         var request = new RestRequest(url + id, Method.PUT);
         request.RequestFormat = DataFormat.Json;
         request.AddHeader("Content-Type", "application/json");
         request.AddJsonBody(superAdmin);
         client.Execute(request);
         return(true);
     } catch (Exception e) {
         return(false);
     }
 }
Example #5
0
 public SuperAdminModel GetById(string id)
 {
     try {
         var client  = new RestClient();
         var request = new RestRequest(url + id, Method.GET);
         request.RequestFormat = DataFormat.Json;
         request.AddHeader("Content-Type", "application/json");
         IRestResponse <SuperAdminModel> response = client.Execute <SuperAdminModel>(request);
         SuperAdminModel superAdmin = response.Data;
         return(superAdmin);
     } catch (Exception e) {
         return(null);
     }
 }
Example #6
0
        //帳密驗證
        private UserClaims VerifyAccountPassword(string userName, string password, string serviceRole)
        {
            UserClaims userClaims = new UserClaims();

            userClaims.IsAuthenticated = false;
            userClaims.CompanyId       = 0;

            switch (serviceRole)
            {
            case APIServiceClient.SuperAdmin:
            {
                SuperAdminModel model = new SuperAdminModel();
                userClaims.IsAuthenticated = model.VerifyPassword(userName, password);
            }
            break;

            case APIServiceClient.Admin:
            {
                EmployeeModel model     = new EmployeeModel();
                int           companyId = model.VerifyPassword(userName, password);

                if (companyId != -1)
                {
                    userClaims.IsAuthenticated = true;
                    userClaims.CompanyId       = companyId;
                }
            }
            break;

            case APIServiceClient.Device:
                AccountModels accountModels = new AccountModels();
                userClaims.IsAuthenticated = accountModels.CheckIoTDevicePassword(userName, password);
                break;

            case APIServiceClient.External:
            {
                CompanyModel model     = new CompanyModel();
                int          companyId = model.GetIdByExtAppAuthenticationKey(password);

                if (companyId != -1)
                {
                    userClaims.IsAuthenticated = true;
                    userClaims.CompanyId       = companyId;
                }
            }
            break;
            }
            return(userClaims);
        }
Example #7
0
 public IHttpActionResult GetSuperAdminById(int id)
 {
     try
     {
         SuperAdminModel model      = new SuperAdminModel();
         var             SuperAdmin = model.GetById(id);
         return(Content(HttpStatusCode.OK, SuperAdmin));
     }
     catch (CDSException cdsEx)
     {
         return(Content(HttpStatusCode.BadRequest, CDSException.GetCDSErrorMessageByCode(cdsEx.ErrorId)));
     }
     catch (Exception ex)
     {
         return(Content(HttpStatusCode.InternalServerError, ex));
     }
 }
Example #8
0
 public IHttpActionResult DeleteSuperAdmin(int id)
 {
     try
     {
         SuperAdminModel model = new SuperAdminModel();
         model.DeleteById(id);
         return(Content(HttpStatusCode.OK, HttpResponseFormat.Success()));
     }
     catch (CDSException cdsEx)
     {
         return(Content(HttpStatusCode.BadRequest, CDSException.GetCDSErrorMessageByCode(cdsEx.ErrorId)));
     }
     catch (Exception ex)
     {
         string        logAPI     = "[Delete] " + Request.RequestUri.ToString();
         StringBuilder logMessage = LogHelper.BuildExceptionMessage(ex);
         Global._appLogger.Error(logAPI + logMessage);
         return(Content(HttpStatusCode.InternalServerError, ex));
     }
 }
Example #9
0
        // GET: Admin/SuperAdmin
        public ActionResult Index()
        {
            SuperAdminModel model = new SuperAdminModel();

            var categories = _db.Categories.Select(c => new { c.CategoryId, c.Category1 });

            ViewBag.Categories = new SelectList(categories.AsEnumerable(), "CategoryId", "Category1");

            ProformaPLPModel ProformaPLPs = new ProformaPLPModel();

            ProformaPLPs.PLPCompanies = GetCompanies();
            model.PLPs = ProformaPLPs;

            model.Events = GetEvents();

            model.Owners = new ProformaOwnersModel();

            model.Analytics = new ProformaAnalyticsModel();

            model.ProExclusives = GetProExclusives();

            return(View(model));
        }
Example #10
0
        public IHttpActionResult GetAllSuperAdmin()
        {
            SuperAdminModel model = new SuperAdminModel();

            return(Content(HttpStatusCode.OK, model.GetAll()));
        }