Exemplo n.º 1
0
        public PostResponse <Attachement> UploadMultipleAttachments(SystemAttachmentsPostRequest request)
        {
            PostResponse <Attachement> response;
            var headers = SessionHelper.GetAuthorizationHeadersForUser();
            PostWebServiceResponse webResponse = childRepo.UploadMultipleAttachments(request.entity, request.FileNames, request.FilesData, headers);

            response = CreateServiceResponse <PostResponse <Attachement> >(webResponse);
            if (webResponse != null)
            {
                response.recordId = webResponse.recordId;
            }
            return(response);
        }
Exemplo n.º 2
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "application/javascript";

            try
            {
                //write your handler implementation here.

                if (context.Request.Files.Count <= 0)
                {
                    PostRequest <Attachement> request = new PostRequest <Attachement>();

                    Attachement at = new Attachement();
                    at.classId  = ClassId.EPEM;
                    at.recordId = Convert.ToInt32(context.Request.QueryString["recordId"]);
                    at.seqNo    = 0;
                    at.folderId = null;

                    at.fileName    = context.Request.Form["oldUrl"];
                    request.entity = at;
                    PostResponse <Attachement> response = _systemService.ChildDelete <Attachement>(request);
                    if (response.Success)
                    {
                        context.Response.Write("{}");
                    }
                    else
                    {
                        context.Response.Write("{Error}");
                    }
                }
                else
                {
                    if (context.Request.QueryString["classId"].ToString() != ClassId.SYDE.ToString())
                    {
                        EmployeeUploadPhotoRequest upreq = new EmployeeUploadPhotoRequest();
                        upreq.entity.fileName = context.Request.Files[0].FileName;
                        byte[] fileData = null;
                        for (int i = 0; i < context.Request.Files.Count; ++i)
                        {
                            HttpPostedFile f = context.Request.Files.Get(i);
                            fileData = new byte[Convert.ToInt32(f.InputStream.Length)];
                            if (f.InputStream.Length > 1435405312)
                            {
                                context.Response.Write("{'Error':'largImage'}");
                                return;
                            }
                            f.InputStream.Seek(0, SeekOrigin.Begin);
                            f.InputStream.Read(fileData, 0, Convert.ToInt32(f.InputStream.Length));
                            f.InputStream.Close();

                            upreq.photoName       = context.Request.Files[0].FileName;
                            upreq.photoData       = fileData;
                            upreq.entity.recordId = Convert.ToInt32(context.Request.QueryString["recordId"]);
                            upreq.entity.date     = DateTime.Now;
                        }

                        PostResponse <Attachement> resp = _employeeService.UploadEmployeePhoto(upreq);
                        if (!resp.Success)
                        {
                            context.Response.Write("{'Error':'Error'}");
                            return;
                        }
                    }
                    else
                    {
                        byte[]         fileData = null;
                        HttpPostedFile f        = context.Request.Files.Get(0);
                        if (f.InputStream.Length > 0)
                        {
                            fileData = new byte[Convert.ToInt32(f.InputStream.Length)];
                            f.InputStream.Seek(0, SeekOrigin.Begin);
                            f.InputStream.Read(fileData, 0, Convert.ToInt32(f.InputStream.Length));
                            f.InputStream.Close();
                        }
                        else
                        {
                            fileData = null;
                        }



                        //check if the insert failed

                        if (fileData != null)
                        {
                            SystemAttachmentsPostRequest req = new SystemAttachmentsPostRequest();
                            if (context.Request.Files.Count == 1)
                            {
                                req.entity = new Model.System.Attachement()
                                {
                                    date = DateTime.Now, classId = ClassId.SYDE, recordId = 1, fileName = context.Request.Files[0].FileName, seqNo = 0
                                }
                            }
                            ;
                            else
                            {
                                req.entity = new Model.System.Attachement()
                                {
                                    date = DateTime.Now, classId = ClassId.SYDE, recordId = 1, fileName = context.Request.Files[0].FileName, seqNo = null
                                }
                            };
                            req.FileNames.Add(context.Request.Files[0].FileName);
                            req.FilesData.Add(fileData);
                            PostResponse <Attachement> resp = _systemService.UploadMultipleAttachments(req);
                            if (!resp.Success)
                            {
                                context.Response.Write("{'Error':'Error'}");
                                return;
                            }
                        }
                    }
                }
                context.Response.Write("{}");
            }
            catch (Exception exp)
            {
                context.Response.Write("{'Error':'Error'}");
            }
        }
Exemplo n.º 3
0
        protected void SaveNewRecord(object sender, DirectEventArgs e)
        {
            string ExpiryDateString    = e.ExtraParams["rwExpiryDate"];
            string IssueDateDateString = e.ExtraParams["rwIssueDate"];

            DateTime ExpiryDate = new DateTime();
            DateTime IssueDate  = new DateTime();

            if (!string.IsNullOrEmpty(ExpiryDateString))
            {
                ExpiryDate = DateTime.Parse(e.ExtraParams["rwExpiryDate"]);
            }
            if (!string.IsNullOrEmpty(IssueDateDateString))
            {
                IssueDate = DateTime.Parse(e.ExtraParams["rwIssueDate"]);
            }

            //Getting the id to check if it is an Add or an edit as they are managed within the same form.
            string obj = e.ExtraParams["values"];
            JsonSerializerSettings settings = new JsonSerializerSettings();

            settings.NullValueHandling = NullValueHandling.Ignore;
            CompanyRightToWork b = JsonConvert.DeserializeObject <CompanyRightToWork>(obj, settings);

            string id  = e.ExtraParams["id"];
            string url = e.ExtraParams["url"];

            // Define the object to add or edit as null

            if (dtId.SelectedItem != null)
            {
                b.dtName = dtId.SelectedItem.Text;
            }

            if (branchId.SelectedItem != null)
            {
                b.branchName = branchId.SelectedItem.Text;
            }
            bool hijriSupported = _systemService.SessionHelper.GetHijriSupport();

            try
            {
                CultureInfo c      = new CultureInfo("en");
                string      format = "";
                if (hijriSupported)
                {
                    if (hijriSelected.Text == "true")
                    {
                        b.hijriCal   = true;
                        c            = new CultureInfo("ar");
                        format       = "yyyy/MM/dd";
                        b.issueDate  = DateTime.ParseExact(rwIssueDateMulti.Text, format, c);
                        b.expiryDate = DateTime.ParseExact(rwExpiryDateMulti.Text, format, c);
                    }
                    //else
                    //{
                    //    c = new CultureInfo("en");
                    //    if (_systemService.SessionHelper.CheckIfArabicSession())
                    //    {

                    //        format = "dd/MM/yyyy";
                    //    }
                    //    else
                    //    {
                    //        format = "MM/dd/yyyy";
                    //    }
                    //}
                    else
                    {
                        b.issueDate = IssueDate;


                        b.expiryDate = ExpiryDate;
                    }
                }
            }
            catch (Exception exp)
            {
                X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                X.Msg.Alert(Resources.Common.Error, GetLocalResourceObject("DateFormatError")).Show();

                return;
            }
            //b.remarks =
            if (b.issueDate != null && (b.issueDate > b.expiryDate))
            {
                X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                X.Msg.Alert(Resources.Common.Error, GetLocalResourceObject("DateRangeError")).Show();

                return;
            }

            if (string.IsNullOrEmpty(id))
            {
                try
                {
                    //New Mode
                    //Step 1 : Fill The object and insert in the store

                    PostRequest <CompanyRightToWork> request = new PostRequest <CompanyRightToWork>();
                    request.entity = b;
                    byte[] fileData = null;
                    if (rwFile.PostedFile != null && rwFile.PostedFile.ContentLength > 0)
                    {
                        //using (var binaryReader = new BinaryReader(picturePath.PostedFile.InputStream))
                        //{
                        //    fileData = binaryReader.ReadBytes(picturePath.PostedFile.ContentLength);
                        //}
                        fileData = new byte[rwFile.PostedFile.ContentLength];
                        fileData = rwFile.FileBytes;
                    }



                    PostResponse <CompanyRightToWork> r = _systemService.ChildAddOrUpdate <CompanyRightToWork>(request);
                    b.recordId = r.recordId;

                    //check if the insert failed
                    if (!r.Success)//it maybe be another condition
                    {
                        //Show an error saving...
                        X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                        Common.errorMessage(r);
                        return;
                    }
                    else
                    {
                        if (fileData != null)
                        {
                            SystemAttachmentsPostRequest req = new SystemAttachmentsPostRequest();
                            req.entity = new Model.System.Attachement()
                            {
                                date = DateTime.Now, classId = ClassId.SYRW, recordId = Convert.ToInt32(b.recordId), fileName = rwFile.PostedFile.FileName, seqNo = 0
                            };
                            req.FileNames.Add(rwFile.PostedFile.FileName);
                            req.FilesData.Add(fileData);
                            PostResponse <Attachement> resp = _systemService.UploadMultipleAttachments(req);
                            if (!resp.Success)//it maybe be another condition
                            {
                                //Show an error saving...
                                X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                                Common.errorMessage(r);
                                return;
                            }
                        }
                        b.recordId = r.recordId;
                        //Add this record to the store
                        CompanyRightToWork m = GetRWById(r.recordId);
                        Store1.Insert(0, m);
                        //Display successful notification
                        Notification.Show(new NotificationConfig
                        {
                            Title = Resources.Common.Notification,
                            Icon  = Icon.Information,
                            Html  = Resources.Common.RecordSavingSucc
                        });

                        this.EditRecordWindow.Close();
                        RowSelectionModel sm = this.GridPanel1.GetSelectionModel() as RowSelectionModel;
                        sm.DeselectAll();
                        sm.Select(b.recordId.ToString());
                    }
                }
                catch (Exception ex)
                {
                    //Error exception displaying a messsage box
                    X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                    X.Msg.Alert(Resources.Common.Error, Resources.Common.ErrorSavingRecord).Show();
                }
            }
            else
            {
                //Update Mode

                try
                {
                    //getting the id of the record
                    int index = Convert.ToInt32(id);//getting the id of the record
                    PostRequest <CompanyRightToWork> request = new PostRequest <CompanyRightToWork>();
                    b.recordId     = index.ToString();;
                    request.entity = b;

                    byte[] fileData = null;
                    if (rwFile.PostedFile != null && rwFile.PostedFile.ContentLength > 0)
                    {
                        fileData = new byte[rwFile.PostedFile.ContentLength];
                        fileData = rwFile.FileBytes;
                    }


                    PostResponse <CompanyRightToWork> r = _systemService.ChildAddOrUpdate <CompanyRightToWork>(request);                      //Step 1 Selecting the object or building up the object for update purpose

                    //Step 2 : saving to store

                    //Step 3 :  Check if request fails
                    if (!r.Success)//it maybe another check
                    {
                        X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                        Common.errorMessage(r);
                        return;
                    }
                    else
                    {
                        if (fileData != null)
                        {
                            SystemAttachmentsPostRequest req = new SystemAttachmentsPostRequest();
                            req.entity = new Model.System.Attachement()
                            {
                                date = DateTime.Now, classId = ClassId.SYRW, recordId = Convert.ToInt32(b.recordId), fileName = rwFile.PostedFile.FileName, seqNo = 0
                            };
                            req.FileNames.Add(rwFile.PostedFile.FileName);
                            req.FilesData.Add(fileData);
                            PostResponse <Attachement> resp = _systemService.UploadMultipleAttachments(req);
                            if (!resp.Success)//it maybe be another condition
                            {
                                //Show an error saving...
                                X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                                Common.errorMessage(r);
                                return;
                            }
                        }
                        CompanyRightToWork m = GetRWById(id);

                        ModelProxy record = this.Store1.GetById(id);
                        BasicInfoTab.UpdateRecord(record);
                        record.Set("dtName", b.dtName);
                        record.Set("branchName", b.branchName);
                        record.Set("fileUrl", m.fileUrl);
                        record.Set("issueDateFormatted", m.issueDateFormatted);
                        record.Set("expireDateFormatted", m.expireDateFormatted);
                        record.Commit();
                        Notification.Show(new NotificationConfig
                        {
                            Title = Resources.Common.Notification,
                            Icon  = Icon.Information,
                            Html  = Resources.Common.RecordUpdatedSucc
                        });
                        this.EditRecordWindow.Close();
                    }
                }
                catch (Exception ex)
                {
                    X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                    X.Msg.Alert(Resources.Common.Error, Resources.Common.ErrorUpdatingRecord).Show();
                }
            }
        }
Exemplo n.º 4
0
        protected void SaveNewRecord(object sender, DirectEventArgs e)
        {
            //Getting the id to check if it is an Add or an edit as they are managed within the same form.
            string    obj = e.ExtraParams["values"];
            MediaItem b   = JsonConvert.DeserializeObject <MediaItem>(obj);

            string id  = e.ExtraParams["id"];
            string url = e.ExtraParams["url"];

            // Define the object to add or edit as null

            if (mcId.SelectedItem != null)
            {
                b.mcName = mcId.SelectedItem.Text;
            }

            if (departmentId.SelectedItem != null)
            {
                b.departmentName = departmentId.SelectedItem.Text;
            }


            if (string.IsNullOrEmpty(id))
            {
                try
                {
                    //New Mode
                    //Step 1 : Fill The object and insert in the store

                    PostRequest <MediaItem> request = new PostRequest <MediaItem>();
                    request.entity = b;
                    byte[] fileData = null;
                    if (rwFile.PostedFile != null && rwFile.PostedFile.ContentLength > 0)
                    {
                        //using (var binaryReader = new BinaryReader(picturePath.PostedFile.InputStream))
                        //{
                        //    fileData = binaryReader.ReadBytes(picturePath.PostedFile.ContentLength);
                        //}
                        fileData = new byte[rwFile.PostedFile.ContentLength];
                        fileData = rwFile.FileBytes;
                    }



                    PostResponse <MediaItem> r = _mediaGalleryService.ChildAddOrUpdate <MediaItem>(request);
                    b.recordId = r.recordId;

                    //check if the insert failed
                    if (!r.Success)//it maybe be another condition
                    {
                        //Show an error saving...
                        X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                        X.Msg.Alert(Resources.Common.Error, GetGlobalResourceObject("Errors", r.ErrorCode) != null ? GetGlobalResourceObject("Errors", r.ErrorCode).ToString() + "<br>" + GetGlobalResourceObject("Errors", "ErrorLogId") + r.LogId : r.Summary).Show();
                        return;
                    }
                    else
                    {
                        if (fileData != null)
                        {
                            SystemAttachmentsPostRequest req = new SystemAttachmentsPostRequest();
                            req.entity = new Model.System.Attachement()
                            {
                                date = DateTime.Now, classId = ClassId.MGME, recordId = Convert.ToInt32(b.recordId), fileName = rwFile.PostedFile.FileName, seqNo = null
                            };
                            req.FileNames.Add(rwFile.PostedFile.FileName);
                            req.FilesData.Add(fileData);
                            PostResponse <Attachement> resp = _systemService.UploadMultipleAttachments(req);
                            if (!resp.Success)//it maybe be another condition
                            {
                                //Show an error saving...
                                X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                                X.Msg.Alert(Resources.Common.Error, GetGlobalResourceObject("Errors", r.ErrorCode) != null ? GetGlobalResourceObject("Errors", r.ErrorCode).ToString() + "<br>" + GetGlobalResourceObject("Errors", "ErrorLogId") + r.LogId : r.Summary).Show();
                                return;
                            }
                        }
                        b.recordId = r.recordId;
                        //Add this record to the store
                        MediaItem m = GetMEById(r.recordId);
                        Store1.Insert(0, m);
                        //Display successful notification
                        Notification.Show(new NotificationConfig
                        {
                            Title = Resources.Common.Notification,
                            Icon  = Icon.Information,
                            Html  = Resources.Common.RecordSavingSucc
                        });

                        this.EditRecordWindow.Close();
                        RowSelectionModel sm = this.GridPanel1.GetSelectionModel() as RowSelectionModel;
                        sm.DeselectAll();
                        sm.Select(b.recordId.ToString());
                    }
                }
                catch (Exception ex)
                {
                    //Error exception displaying a messsage box
                    X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                    X.Msg.Alert(Resources.Common.Error, Resources.Common.ErrorSavingRecord).Show();
                }
            }
            else
            {
                //Update Mode

                try
                {
                    //getting the id of the record
                    int index = Convert.ToInt32(id);//getting the id of the record
                    PostRequest <MediaItem> request = new PostRequest <MediaItem>();
                    request.entity = b;
                    byte[] fileData = null;
                    if (rwFile.PostedFile != null && rwFile.PostedFile.ContentLength > 0)
                    {
                        fileData = new byte[rwFile.PostedFile.ContentLength];
                        fileData = rwFile.FileBytes;
                    }


                    PostResponse <MediaItem> r = _mediaGalleryService.ChildAddOrUpdate <MediaItem>(request);                      //Step 1 Selecting the object or building up the object for update purpose

                    //Step 2 : saving to store

                    //Step 3 :  Check if request fails
                    if (!r.Success)//it maybe another check
                    {
                        X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                        X.Msg.Alert(Resources.Common.Error, GetGlobalResourceObject("Errors", r.ErrorCode) != null ? GetGlobalResourceObject("Errors", r.ErrorCode).ToString() + "<br>" + GetGlobalResourceObject("Errors", "ErrorLogId") + r.LogId : r.Summary).Show();
                        return;
                    }
                    else
                    {
                        if (fileData != null)
                        {
                            SystemAttachmentsPostRequest req = new SystemAttachmentsPostRequest();
                            req.entity = new Model.System.Attachement()
                            {
                                date = DateTime.Now, classId = ClassId.MGME, recordId = Convert.ToInt32(b.recordId), fileName = rwFile.PostedFile.FileName, seqNo = 0
                            };
                            req.FileNames.Add(rwFile.PostedFile.FileName);
                            req.FilesData.Add(fileData);
                            PostResponse <Attachement> resp = _systemService.UploadMultipleAttachments(req);
                            if (!resp.Success)//it maybe be another condition
                            {
                                //Show an error saving...
                                X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                                X.Msg.Alert(Resources.Common.Error, GetGlobalResourceObject("Errors", r.ErrorCode) != null ? GetGlobalResourceObject("Errors", r.ErrorCode).ToString() + "<br>" + GetGlobalResourceObject("Errors", "ErrorLogId") + r.LogId : r.Summary).Show();
                                return;
                            }
                        }
                        MediaItem m = GetMEById(id);

                        ModelProxy record = this.Store1.GetById(id);
                        BasicInfoTab.UpdateRecord(record);
                        record.Set("mcName", b.mcName);
                        record.Set("departmentName", b.departmentName);
                        recordId.Set("pictureUrl", m.pictureUrl);
                        record.Commit();
                        Notification.Show(new NotificationConfig
                        {
                            Title = Resources.Common.Notification,
                            Icon  = Icon.Information,
                            Html  = Resources.Common.RecordUpdatedSucc
                        });
                        this.EditRecordWindow.Close();
                    }
                }
                catch (Exception ex)
                {
                    X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                    X.Msg.Alert(Resources.Common.Error, Resources.Common.ErrorUpdatingRecord).Show();
                }
            }
        }
Exemplo n.º 5
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "application/javascript";

            if (context.Request.Files.Count <= 0)
            {
                PostRequest <Attachement> request = new PostRequest <Attachement>();

                Attachement at = new Attachement();
                at.classId  = ClassId.EPEM;
                at.recordId = Convert.ToInt32(context.Request.QueryString["recordId"]);
                at.seqNo    = 0;
                at.folderId = null;

                at.fileName    = context.Request.Form["oldUrl"];
                request.entity = at;
                PostResponse <Attachement> response = _systemService.ChildDelete <Attachement>(request);
                if (response.Success)
                {
                    context.Response.Write("{}");
                }
                else
                {
                    context.Response.Write("{Error}");
                }
            }
            SystemAttachmentsPostRequest req = new SystemAttachmentsPostRequest();

            if (ClassId.EPDO == Convert.ToInt32(context.Request.QueryString["classId"]))
            {
                req.entity = new Model.System.Attachement()
                {
                    date = DateTime.Now, classId = Convert.ToInt32(context.Request.QueryString["classId"]), recordId = Convert.ToInt32(context.Request.QueryString["recordId"]), fileName = Regex.Replace(context.Request.Files[0].FileName, @"[^0-9a-zA-Z.]+", ""), seqNo = null
                }
            }
            ;
            else
            {
                if (context.Request.Files.Count == 1)
                {
                    req.entity = new Model.System.Attachement()
                    {
                        date = DateTime.Now, classId = Convert.ToInt32(context.Request.QueryString["classId"]), recordId = Convert.ToInt32(context.Request.QueryString["recordId"]), fileName = Regex.Replace(context.Request.Files[0].FileName, @"[^0-9a-zA-Z.]+", ""), seqNo = 0
                    }
                }
                ;
                else
                {
                    req.entity = new Model.System.Attachement()
                    {
                        date = DateTime.Now, classId = Convert.ToInt32(context.Request.QueryString["classId"]), recordId = Convert.ToInt32(context.Request.QueryString["recordId"]), fileName = Regex.Replace(context.Request.Files[0].FileName, @"[^0-9a-zA-Z.]+", ""), seqNo = null
                    }
                };
            }
            //write your handler implementation here.
            int bulk;

            if (int.TryParse(context.Request.Form["id"], out bulk))
            {
                req.entity.folderId = bulk;
            }
            else
            {
                req.entity.folderId = null;
            }


            byte[] fileData = null;
            for (int i = 0; i < context.Request.Files.Count; ++i)
            {
                HttpPostedFile f = context.Request.Files.Get(i);
                fileData = new byte[Convert.ToInt32(f.InputStream.Length)];
                f.InputStream.Seek(0, SeekOrigin.Begin);
                f.InputStream.Read(fileData, 0, Convert.ToInt32(f.InputStream.Length));
                f.InputStream.Close();

                req.FilesData.Add((byte[])fileData.Clone());
                req.FileNames.Add(Regex.Replace(f.FileName, @"[^0-9a-zA-Z.]+", ""));
            }

            PostResponse <Attachement> resp = _systemService.UploadMultipleAttachments(req);

            if (!resp.Success)
            {
                context.Response.Write("{'Error':'Error'}");
                return;
            }


            context.Response.Write("{}");
        }
Exemplo n.º 6
0
        protected void SaveBC(object sender, DirectEventArgs e)
        {
            //Getting the id to check if it is an Add or an edit as they are managed within the same form.
            string id = e.ExtraParams["id"];

            string obj                = e.ExtraParams["values"];
            string bcFileURl          = e.ExtraParams["BcFile"];
            EmployeeBackgroundCheck b = JsonConvert.DeserializeObject <EmployeeBackgroundCheck>(obj);

            b.fileUrl = bcFileURl;
            if (!string.IsNullOrEmpty(b.fileUrl))
            {
                b.fileUrl = Regex.Replace(b.fileUrl, @"[^0-9a-zA-Z.]+", "");
            }
            b.employeeId = Convert.ToInt32(CurrentEmployee.Text);
            b.recordId   = id;
            b.date       = new DateTime(b.date.Year, b.date.Month, b.date.Day, 14, 0, 0);
            b.expiryDate = new DateTime(b.expiryDate.Year, b.expiryDate.Month, b.expiryDate.Day, 14, 0, 0);

            if (ctId.SelectedItem != null)
            {
                b.ctName = ctId.SelectedItem.Text;
            }

            if (string.IsNullOrEmpty(id))
            {
                try
                {
                    //New Mode
                    //Step 1 : Fill The object and insert in the store
                    PostRequest <EmployeeBackgroundCheck> request = new PostRequest <EmployeeBackgroundCheck>();
                    request.entity = b;
                    byte[] fileData = null;
                    if (bcFile.PostedFile != null && bcFile.PostedFile.ContentLength > 0)
                    {
                        //using (var binaryReader = new BinaryReader(picturePath.PostedFile.InputStream))
                        //{
                        //    fileData = binaryReader.ReadBytes(picturePath.PostedFile.ContentLength);
                        //}
                        fileData = new byte[bcFile.PostedFile.ContentLength];
                        fileData = bcFile.FileBytes;
                    }
                    else
                    {
                        fileData = null;
                    }
                    PostResponse <EmployeeBackgroundCheck> r = _employeeService.ChildAddOrUpdate <EmployeeBackgroundCheck>(request);
                    b.recordId = r.recordId;

                    //check if the insert failed
                    if (!r.Success)//it maybe be another condition
                    {
                        //Show an error saving...
                        X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                        Common.errorMessage(r);
                        return;
                    }
                    else
                    {
                        //Add this record to the store
                        if (fileData != null)
                        {
                            SystemAttachmentsPostRequest req = new SystemAttachmentsPostRequest();
                            req.entity = new Model.System.Attachement()
                            {
                                date = DateTime.Now, classId = ClassId.EPBC, recordId = Convert.ToInt32(b.recordId), fileName = bcFile.PostedFile.FileName, seqNo = 0
                            };
                            req.FileNames.Add(bcFile.PostedFile.FileName);
                            req.FilesData.Add(fileData);
                            PostResponse <Attachement> resp = _systemService.UploadMultipleAttachments(req);
                            if (!resp.Success)//it maybe be another condition
                            {
                                //Show an error saving...
                                X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                                Common.errorMessage(r);
                                return;
                            }
                        }
                        EmployeeBackgroundCheck bc = GetBCById(r.recordId);
                        this.BCStore.Insert(0, bc);
                        //Display successful notification
                        Notification.Show(new NotificationConfig
                        {
                            Title = Resources.Common.Notification,
                            Icon  = Icon.Information,
                            Html  = Resources.Common.RecordSavingSucc
                        });

                        this.EditBCWindow.Close();
                        RowSelectionModel sm = this.BackgroundCheckGrid.GetSelectionModel() as RowSelectionModel;
                        sm.DeselectAll();
                        sm.Select(b.recordId.ToString());
                    }
                }
                catch (Exception ex)
                {
                    //Error exception displaying a messsage box
                    X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                    X.Msg.Alert(Resources.Common.Error, Resources.Common.ErrorSavingRecord).Show();
                }
            }
            else
            {
                //Update Mode

                try
                {
                    int index = Convert.ToInt32(id);//getting the id of the record
                    PostRequest <EmployeeBackgroundCheck> request = new PostRequest <EmployeeBackgroundCheck>();
                    request.entity = b;
                    byte[] fileData = null;

                    if (bcFile.PostedFile != null && bcFile.PostedFile.ContentLength > 0)
                    {
                        //using (var binaryReader = new BinaryReader(picturePath.PostedFile.InputStream))
                        //{
                        //    fileData = binaryReader.ReadBytes(picturePath.PostedFile.ContentLength);
                        //}
                        fileData = new byte[bcFile.PostedFile.ContentLength];
                        fileData = bcFile.FileBytes;
                    }

                    PostResponse <EmployeeBackgroundCheck> r = _employeeService.ChildAddOrUpdate <EmployeeBackgroundCheck>(request);                      //Step 1 Selecting the object or building up the object for update purpose

                    //Step 2 : saving to store

                    //Step 3 :  Check if request fails
                    if (!r.Success)//it maybe another check
                    {
                        X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                        Common.errorMessage(r);
                        return;
                    }
                    else
                    {
                        if (fileData != null)
                        {
                            SystemAttachmentsPostRequest req = new SystemAttachmentsPostRequest();
                            req.entity = new Model.System.Attachement()
                            {
                                date = DateTime.Now, classId = ClassId.EPBC, recordId = Convert.ToInt32(b.recordId), fileName = bcFile.PostedFile.FileName, seqNo = 0
                            };
                            req.FileNames.Add(Regex.Replace(bcFile.PostedFile.FileName, @"[^0-9a-zA-Z.]+", ""));
                            req.FilesData.Add(fileData);
                            PostResponse <Attachement> resp = _systemService.UploadMultipleAttachments(req);
                            if (!resp.Success)//it maybe be another condition
                            {
                                //Show an error saving...
                                X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                                Common.errorMessage(r);
                                return;
                            }
                        }
                        EmployeeBackgroundCheck BC = GetBCById(b.recordId);
                        ModelProxy record          = this.BCStore.GetById(id);
                        record.Set("expiryDate", BC.expiryDate);

                        record.Set("fileUrl", BC.fileUrl);

                        record.Set("ctId", BC.ctId);
                        record.Set("ctName", BC.ctName);
                        record.Set("remarks", BC.remarks);

                        record.Commit();

                        Notification.Show(new NotificationConfig
                        {
                            Title = Resources.Common.Notification,
                            Icon  = Icon.Information,
                            Html  = Resources.Common.RecordUpdatedSucc
                        });
                        this.EditBCWindow.Close();
                    }
                }
                catch (Exception ex)
                {
                    X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                    X.Msg.Alert(Resources.Common.Error, Resources.Common.ErrorUpdatingRecord).Show();
                }
            }
            //if (b.Date.Date == DateTime.Today)
            //{
            //    X.Call("parent.FillLeftPanel", b.departmentName + "<br/>", b.branchName + "<br/>", b.positionName + "<br/>");
            //    X.Call("parent.SelectJICombos", b.departmentId, b.branchId, b.positionId, b.divisionId);
            //}
        }