Example #1
0
        public async Task <string> UpdateEmployeeEmergencyContact(int id, EmployeeEmergencyContact employeeEmergencyContact)
        {
            try
            {
                var res = await _repository.UpdateEmployeeEmergencyContact(id, employeeEmergencyContact);

                return(res);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public async Task <IActionResult> Create(string employeeId, [Bind("Id,EmployeeId,FirstName,LastName,PhoneNumber,Email,PhoneType,RelationshipToEmployee")] EmployeeEmergencyContact employeeEmergencyContact)
        {
            if (ModelState.IsValid)
            {
                _context.Add(employeeEmergencyContact);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index), new
                {
                    employeeId
                }));
            }
            return(View(employeeEmergencyContact));
        }
Example #3
0
        protected void PoPuPEC(object sender, DirectEventArgs e)
        {
            int    id   = Convert.ToInt32(e.ExtraParams["id"]);
            string type = e.ExtraParams["type"];

            switch (type)
            {
            case "imgEdit":
                //Step 1 : get the object from the Web Service
                EmployeeEmergencyContact entity = GetECById(id.ToString());
                //Step 2 : call setvalues with the retrieved object
                this.EmergencyContactsForm.SetValues(entity);
                FillRelationshipType();
                rtId.Select(entity.rtId.ToString());

                FillECNationality();
                ecnaId.Select(entity.address.countryId);
                FillECState();
                ecstId.Select(entity.address.stateId);
                street1.Text     = entity.address.street1;
                street2.Text     = entity.address.street2;
                postalCode.Text  = entity.address.postalCode;
                city.Text        = entity.address.city;
                ecaddressId.Text = entity.address.recordId;


                this.EditEmergencyContactWindow.Title = Resources.Common.EditWindowsTitle;
                this.EditEmergencyContactWindow.Show();
                break;

            case "imgDelete":
                X.Msg.Confirm(Resources.Common.Confirmation, Resources.Common.DeleteOneRecord, new MessageBoxButtonsConfig
                {
                    Yes = new MessageBoxButtonConfig
                    {
                        //We are call a direct request metho for deleting a record
                        Handler = String.Format("App.direct.DeleteEC({0})", id),
                        Text    = Resources.Common.Yes
                    },
                    No = new MessageBoxButtonConfig
                    {
                        Text = Resources.Common.No
                    }
                }).Show();
                break;

            default:
                break;
            }
        }
Example #4
0
        public async Task <IActionResult> CreateEmployeeEmergencyContact(EmployeeEmergencyContact employeeEmergencyContact)
        {
            try
            {
                var response = await _service.CreateNewEmployeeEmergencyContact(employeeEmergencyContact);

                if (response != null)
                {
                    return(Ok(response));
                }
                return(StatusCode(StatusCodes.Status204NoContent));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public async Task <string> UpdateEmployeeEmergencyContact(int id, EmployeeEmergencyContact employeeEmergencyContact)
        {
            try
            {
                var res = await _context.EmployeeEmergencyContacts.FirstOrDefaultAsync(m => m.EmployeeContactId == id);

                res.EmployeeName = employeeEmergencyContact.EmployeeName;
                res.Name         = employeeEmergencyContact.Name;
                res.Relationship = employeeEmergencyContact.Relationship;
                res.HomePhone    = employeeEmergencyContact.HomePhone;
                res.WorkPhone    = employeeEmergencyContact.WorkPhone;
                res.MobilePhone  = employeeEmergencyContact.MobilePhone;
                _context.Update(res);
                await _context.SaveChangesAsync();

                return("Updated Record");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #6
0
        public void DeleteEC(string index)
        {
            try
            {
                //Step 1 Code to delete the object from the database
                EmployeeEmergencyContact n = new EmployeeEmergencyContact();
                n.recordId = index;

                PostRequest <EmployeeEmergencyContact> req = new PostRequest <EmployeeEmergencyContact>();
                req.entity = n;
                PostResponse <EmployeeEmergencyContact> res = _employeeService.ChildDelete <EmployeeEmergencyContact>(req);
                if (!res.Success)
                {
                    //Show an error saving...
                    X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                    X.Msg.Alert(Resources.Common.Error, res.Summary).Show();
                    return;
                }
                else
                {
                    //Step 2 :  remove the object from the store
                    emergencyContactStore.Remove(index);

                    //Step 3 : Showing a notification for the user
                    Notification.Show(new NotificationConfig
                    {
                        Title = Resources.Common.Notification,
                        Icon  = Icon.Information,
                        Html  = Resources.Common.RecordDeletedSucc
                    });
                }
            }
            catch (Exception ex)
            {
                //In case of error, showing a message box to the user
                X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                X.Msg.Alert(Resources.Common.Error, Resources.Common.ErrorDeletingRecord).Show();
            }
        }
        public async Task <IActionResult> Edit(string employeeId, int emergencyContactId, [Bind("Id,EmployeeId,FirstName,LastName,PhoneNumber,Email,PhoneType,RelationshipToEmployee")] EmployeeEmergencyContact employeeEmergencyContact)
        {
            if (employeeId != employeeEmergencyContact.EmployeeId && emergencyContactId == employeeEmergencyContact.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(employeeEmergencyContact);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!await EmployeeEmergencyContactExistsAsync(employeeId, emergencyContactId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index), new
                {
                    employeeId
                }));
            }
            return(View(employeeEmergencyContact));
        }
Example #8
0
        public async Task <IActionResult> UpdateEmployeeEmergencyContact(int EmployeeEmergencyContactId, EmployeeEmergencyContact employeeEmergencyContact)
        {
            try
            {
                var res = await _service.UpdateEmployeeEmergencyContact(EmployeeEmergencyContactId, employeeEmergencyContact);

                if (res != null)
                {
                    return(Ok(res));
                }
                return(StatusCode(StatusCodes.Status204NoContent));
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Example #9
0
        public async Task <EmployeeEmergencyContact> CreateNewEmployeeEmergencyContact(EmployeeEmergencyContact employeeEmergencyContact)
        {
            try
            {
                var res = await _repository.CreateNewEmployeeEmergencyContact(employeeEmergencyContact);

                return(res);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public async Task <EmployeeEmergencyContact> CreateNewEmployeeEmergencyContact(EmployeeEmergencyContact employeeEmergencyContact)
        {
            try
            {
                _context.EmployeeEmergencyContacts.Add(employeeEmergencyContact);
                await _context.SaveChangesAsync();

                return(employeeEmergencyContact);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #11
0
        protected void SaveEC(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"];
            JsonSerializerSettings settings = new JsonSerializerSettings();
            CustomResolver         res      = new CustomResolver();

            res.AddRule("ecnaId", "naId");
            res.AddRule("ecstId", "stateId");
            settings.ContractResolver = res;
            EmployeeEmergencyContact b = JsonConvert.DeserializeObject <EmployeeEmergencyContact>(obj, settings);

            b.employeeId = Convert.ToInt32(CurrentEmployee.Text);
            b.recordId   = id;
            // Define the object to add or edit as null
            b.rtName  = rtId.SelectedItem.Text;
            b.address = new AddressBook()
            {
                street1 = street1.Text, street2 = street2.Text, city = city.Text, postalCode = postalCode.Text, countryId = b.naId, countryName = ecnaId.SelectedItem.Text, stateId = b.stateId
            };
            b.employeeId       = Convert.ToInt32(CurrentEmployee.Text);
            b.address.recordId = ecaddressId.Text;
            if (string.IsNullOrEmpty(id))
            {
                try
                {
                    //New Mode
                    PostRequest <EmployeeEmergencyContact> request = new PostRequest <EmployeeEmergencyContact>();
                    request.entity = b;

                    PostResponse <EmployeeEmergencyContact> r = _employeeService.ChildAddOrUpdate <EmployeeEmergencyContact>(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
                        emergencyContactStore.Reload();

                        //Display successful notification
                        Notification.Show(new NotificationConfig
                        {
                            Title     = Resources.Common.Notification,
                            Icon      = Icon.Information,
                            Html      = Resources.Common.RecordSavingSucc,
                            HideDelay = 250
                        });

                        this.EditEmergencyContactWindow.Close();
                    }
                }
                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 <EmployeeEmergencyContact> request = new PostRequest <EmployeeEmergencyContact>();
                    request.entity = b;



                    PostResponse <EmployeeEmergencyContact> r = _employeeService.ChildAddOrUpdate <EmployeeEmergencyContact>(request);


                    //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
                    {
                        emergencyContactStore.Reload();
                        Notification.Show(new NotificationConfig
                        {
                            Title = Resources.Common.Notification,
                            Icon  = Icon.Information,
                            Html  = Resources.Common.RecordUpdatedSucc
                            ,
                            HideDelay = 250
                        });
                        this.EditEmergencyContactWindow.Close();
                    }
                }
                catch (Exception ex)
                {
                    X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                    X.Msg.Alert(Resources.Common.Error, Resources.Common.ErrorUpdatingRecord).Show();
                }
            }
        }