예제 #1
0
        private async Task UpdateLeaveSchedule(AnnualLeave item)
        {
            // Добавляем информацию о графике отпусков
            LeaveSchedule leaveSchedule = await Database.LeaveSchedules.GetFirstAsync(ls => ls.Year == item.ScheduledDate.Value.Year);

            item.LeaveScheduleId = leaveSchedule.Id;
        }
예제 #2
0
        // Добавление нового графика отпусков (с валидацией)
        public override async Task CreateAsync(LeaveScheduleDTO leaveScheduleDto)
        {
            await ValidationLeaveSchedule(leaveScheduleDto);

            InitializeMapperDTO();
            LeaveSchedule leaveSchedule = Mapper.Map <LeaveScheduleDTO, LeaveSchedule>(leaveScheduleDto);

            Database.LeaveSchedules.Create(leaveSchedule);
            await Database.SaveAsync();
        }
예제 #3
0
        // Обновление информации о графике отпусков
        public override async Task EditAsync(LeaveScheduleDTO leaveScheduleDto)
        {
            await ValidationLeaveSchedule(leaveScheduleDto);

            LeaveSchedule leaveSchedule = await Database.LeaveSchedules.FindByIdAsync(leaveScheduleDto.Id);

            if (leaveSchedule == null)
            {
                return;
            }
            InitializeMapperDTO();
            Mapper.Map(leaveScheduleDto, leaveSchedule);
            Database.LeaveSchedules.Update(leaveSchedule);
            await Database.SaveAsync();
        }
예제 #4
0
        // Удаление графика отпусков
        public override async Task DeleteAsync(int id)
        {
            LeaveSchedule leaveSchedule = await Database.LeaveSchedules.FindByIdAsync(id);

            if (leaveSchedule == null)
            {
                return;
            }
            if (leaveSchedule.AnnualLeaves.Count > 0)
            {
                throw new ValidationException("Нельзя удалить график отпусков", "");
            }
            Database.LeaveSchedules.Remove(leaveSchedule);
            await Database.SaveAsync();
        }
예제 #5
0
        // Получение графика отпусков по id
        public override async Task <LeaveScheduleDTO> FindByIdAsync(int?id)
        {
            if (id == null)
            {
                throw new ValidationException("Не установлен id графика", "");
            }
            LeaveSchedule leaveSchedule = await Database.LeaveSchedules.FindByIdAsync(id.Value);

            if (leaveSchedule == null)
            {
                throw new ValidationException("График не найден", "");
            }
            InitializeMapper();
            LeaveScheduleDTO leaveScheduleDto = Mapper.Map <LeaveSchedule, LeaveScheduleDTO>(leaveSchedule);

            return(leaveScheduleDto);
        }
예제 #6
0
        public void DeleteRecord(string index)
        {
            try
            {
                //Step 1 Code to delete the object from the database
                LeaveSchedule s = new LeaveSchedule();
                s.recordId = index;
                s.name     = "";

                PostRequest <LeaveSchedule> req = new PostRequest <LeaveSchedule>();
                req.entity = s;
                PostResponse <LeaveSchedule> r = _branchService.ChildDelete <LeaveSchedule>(req);
                if (!r.Success)
                {
                    X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                    Common.errorMessage(r);
                    return;
                }
                else
                {
                    //Step 2 :  remove the object from the store
                    Store1.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();
            }
        }
예제 #7
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 id = e.ExtraParams["id"];

            string        obj  = e.ExtraParams["schedule"];
            LeaveSchedule b    = JsonConvert.DeserializeObject <LeaveSchedule>(obj);
            string        pers = e.ExtraParams["periods"];

            b.recordId = id;
            // Define the object to add or edit as null

            if (string.IsNullOrEmpty(id))
            {
                try
                {
                    //New Mode
                    //Step 1 : Fill The object and insert in the store
                    PostRequest <LeaveSchedule> request = new PostRequest <LeaveSchedule>();
                    request.entity = b;
                    PostResponse <LeaveSchedule> r = _branchService.ChildAddOrUpdate <LeaveSchedule>(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;
                    }
                    List <LeaveSchedulePeriod> periods = JsonConvert.DeserializeObject <List <LeaveSchedulePeriod> >(pers);
                    bool Success = AddPeriodsList(b.recordId, periods);


                    if (Success)
                    {
                        //Add this record to the store
                        this.Store1.Insert(0, b);

                        //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
                {
                    int index = Convert.ToInt32(id);//getting the id of the record
                    PostRequest <LeaveSchedule> modifyHeaderRequest = new PostRequest <LeaveSchedule>();
                    modifyHeaderRequest.entity = b;
                    PostResponse <LeaveSchedule> r = _branchService.ChildAddOrUpdate <LeaveSchedule>(modifyHeaderRequest); //Step 1 Selecting the object or building up the object for update purpose
                    if (!r.Success)                                                                                        //it maybe another check
                    {
                        X.MessageBox.ButtonText.Ok = Resources.Common.Ok;
                        X.Msg.Alert(Resources.Common.Error, Resources.Common.ErrorUpdatingRecord).Show();
                        return;
                    }
                    LeaveSchedulesListRequest leaveScheduleReq = new LeaveSchedulesListRequest();
                    leaveScheduleReq.LeaveScheduleId = b.recordId;
                    ListResponse <LeaveSchedulePeriod> leaveScheduleResponse = _branchService.ChildGetAll <LeaveSchedulePeriod>(leaveScheduleReq);

                    leaveScheduleResponse.Items.ForEach(x =>
                    {
                        PostRequest <LeaveSchedulePeriod> LeaveScheduleDEleteRequest = new PostRequest <LeaveSchedulePeriod>();
                        LeaveScheduleDEleteRequest.entity = x;
                        PostResponse <LeaveSchedulePeriod> LeaveScheduleDEleteResponse = _branchService.ChildDelete <LeaveSchedulePeriod>(LeaveScheduleDEleteRequest);
                        if (!LeaveScheduleDEleteResponse.Success)
                        {
                            Common.errorMessage(LeaveScheduleDEleteResponse);
                            throw new Exception();
                        }
                    });

                    List <LeaveSchedulePeriod> periods = JsonConvert.DeserializeObject <List <LeaveSchedulePeriod> >(pers);
                    bool result = AddPeriodsList(b.recordId, periods);

                    //Step 2 : saving to store

                    //Step 3 :  Check if request fails
                    if (result)
                    {
                        ModelProxy record = this.Store1.GetById(index);
                        BasicInfoTab.UpdateRecord(record);

                        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();
                }
            }
        }