Exemplo n.º 1
0
        public async Task <HttpResponseMessage> DetectFace()
        {
            string imageLink = string.Empty;

            try
            {
                var                modelJson       = HttpContext.Current.Request.Form["Model"];
                DetectFaceModel    detectFaceModel = JsonConvert.DeserializeObject <DetectFaceModel>(modelJson);
                HttpFileCollection hfc             = HttpContext.Current.Request.Files;
                if (hfc.Count > 0)
                {
                    detectFaceModel.ImageStream  = hfc[0].InputStream;
                    detectFaceModel.LogImageLink = imageLink = UploadFileServer.UploadFileJPG(hfc[0], Constants.FolderLogAttendance);
                }
                var ipClient = GetIpClient.GetClientIpAddress(Request);
                detectFaceModel.ClientIPAddress = ipClient;
                DetectFaceResultModel result = await faceHelperBusiness.DetectFace(detectFaceModel);

                return(Request.CreateResponse(HttpStatusCode.OK, result));
            }
            catch (Exception ex)
            {
                UploadFileServer.DeleteFile(imageLink);
                logger.Error(ex.Message, ex.InnerException);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
        //[NTSAuthorize(AllowFeature = "SY0002")]
        public HttpResponseMessage CreateUser()
        {
            var                modelJson = HttpContext.Current.Request.Form["Model"];
            UserModel          model     = JsonConvert.DeserializeObject <UserModel>(modelJson);
            HttpFileCollection hfc       = HttpContext.Current.Request.Files;

            string imageLink = string.Empty;

            try
            {
                if (hfc.Count > 0)
                {
                    imageLink = Task.Run(async() =>
                    {
                        return(await AzureStorageUploadFiles.GetInstance().UploadPhotoAsync(hfc[0], hfc[0].FileName, Constants.FolderImageUser));
                    }).Result;
                    // imageLink = UploadFileServer.UploadFile(hfc[0], Constants.FolderImageUser);
                }

                model.ImageLink = imageLink;
                _userBusiness.CreateUser(model);

                return(Request.CreateResponse(HttpStatusCode.OK, string.Empty));
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message, ex.InnerException);

                //Xóa file trên server nếu cập nhật lỗi
                UploadFileServer.DeleteFile(imageLink);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
        public HttpResponseMessage CreateEmployee()
        {
            var                modelJson        = HttpContext.Current.Request.Form["Model"];
            EmployeeModel      model            = JsonConvert.DeserializeObject <EmployeeModel>(modelJson);
            HttpFileCollection hfc              = HttpContext.Current.Request.Files;
            string             pathFolder       = "fileUpload/" + Constants.FolderEmployee + "/";
            string             pathFolderServer = HostingEnvironment.MapPath("~/" + pathFolder);
            string             imageLink        = string.Empty;

            try
            {
                if (hfc.Count > 0)
                {
                    for (int i = 0; i < hfc.Count; i++)
                    {
                        if (i == 0)
                        {
                            // imageLink = Task.Run(async () => { return wait UploadPhotoAsync(hfc[i], hfc[i].FileName); }).Result;

                            imageLink = Task.Run(async() =>
                            {
                                return(await AzureStorageUploadFiles.GetInstance().UploadPhotoAsync(hfc[i], hfc[i].FileName, Constants.FolderEmployee));
                            }).Result;
                        }
                        else
                        {
                            imageLink += ";" + Task.Run(async() =>
                            {
                                return(await AzureStorageUploadFiles.GetInstance().UploadPhotoAsync(hfc[i], hfc[i].FileName, Constants.FolderEmployee));
                            }).Result;
                        }
                    }
                }

                model.LinkImage = imageLink;
                _userBusiness.CreateEmployee(model);

                return(Request.CreateResponse(HttpStatusCode.OK, string.Empty));
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message, ex.InnerException);
                //Xóa file trên server nếu cập nhật lỗi
                string[] mangErro = imageLink.Split(';');
                for (int i = 0; i < mangErro.Length; i++)
                {
                    UploadFileServer.DeleteFile(mangErro[i]);
                }
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
            }
        }
 public HttpResponseMessage DeleteEmployee(string id, string CreateBy)
 {
     try
     {
         var img = _userBusiness.DeleteEmployee(id, CreateBy);
         if (!string.IsNullOrEmpty(img))
         {
             string[] mang = img.Split(';');
             for (int i = 0; i < mang.Length; i++)
             {
                 if (!string.IsNullOrEmpty(mang[i]))
                 {
                     UploadFileServer.DeleteFile(mang[i]);
                 }
             }
         }
         return(Request.CreateResponse(HttpStatusCode.OK, string.Empty));
     }
     catch (Exception ex)
     {
         logger.Error(ex.Message, ex.InnerException);
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
     }
 }