예제 #1
0
        public async Task CreateLeave(Leave leave, int leaderMaxLevel, Approver approver)
        {
            leave.LeaderMaxLevel = leaderMaxLevel;
            leave.Approver       = approver;
            leave.Create();

            _leaveRepository.Save(_leaveFactory.CreateLeavePO(leave));

            var leaveEvent = new LeaveEvent(LeaveEventType.CREATE_EVENT, leave);

            _leaveRepository.SaveEvent(_leaveFactory.CreateLeaveEventPO(leaveEvent));

            var successCount = await _leaveRepository.UnitOfWork.SaveChangesAsync();

            if (successCount > 0)
            {
                _eventPublisher.Publish(DomainEventKeys.LeaveCreatedEventKey, leaveEvent);
            }
        }
예제 #2
0
        public ContentResult Create(FormCollection form)
        {
            JObject json = new JObject();

            json["error"]   = false;
            json["message"] = "";

            string[] keys = new string[]
            {
                "start-month", "start-day", "start-year", "end-month", "end-day", "end-year", "reason", "type"
            };

            if (!this.CheckLogin(AccountType.Applicant))
            {
                if (this.HasValues(form, keys))
                {
                    try
                    {
                        Leave  l     = new Leave();
                        string start = (Int32.Parse(form.GetValue("start-month").AttemptedValue) + 1).ToString("00") + "/"
                                       + (Int32.Parse(form.GetValue("start-day").AttemptedValue) + 1).ToString("00") + "/"
                                       + form.GetValue("start-year").AttemptedValue;
                        string end = (Int32.Parse(form.GetValue("end-month").AttemptedValue) + 1).ToString("00") + "/"
                                     + (Int32.Parse(form.GetValue("end-day").AttemptedValue) + 1).ToString("00") + "/"
                                     + form.GetValue("end-year").AttemptedValue;

                        l.Employee  = (Employee)this.GetAccount().Profile;
                        l.StartDate = DateTime.ParseExact(start, "MM/dd/yyyy", CultureInfo.InvariantCulture);
                        l.EndDate   = DateTime.ParseExact(end, "MM/dd/yyyy", CultureInfo.InvariantCulture);
                        l.Status    = LeaveStatus.Pending;
                        l.Reason    = form.GetValue("reason").AttemptedValue;
                        l.Type      = (LeaveType)Int32.Parse(form.GetValue("type").AttemptedValue);

                        l.Create();

                        DBHandler db = new DBHandler();
                        using (DataTable dt = db.Execute <DataTable>(
                                   CRUD.READ,
                                   "SELECT E.Profile FROM Employee E INNER JOIN Department D ON E.Department = D.DepartmentID WHERE D.Type = "
                                   + ((int)DepartmentType.HumanResources)))
                        {
                            foreach (DataRow row in dt.Rows)
                            {
                                Notification notifHR = new Notification();
                                notifHR.Account = new Account().FindByProfile(Int32.Parse(row["Profile"].ToString()));

                                if (this.GetAccount().Profile.Profile.ProfileID != notifHR.Account.AccountID)
                                {
                                    notifHR.TimeStamp = DateTime.Now;
                                    notifHR.Status    = NotificationStatus.Unread;

                                    notifHR.Message = l.Employee.Profile.FirstName + " " + l.Employee.Profile.MiddleName
                                                      + " " + l.Employee.Profile.LastName + " applied for a sick leave on "
                                                      + start + " - " + end;
                                    notifHR.Create();
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        json["error"]   = true;
                        json["message"] = e.Message;
                    }
                }
                else
                {
                    json["error"]   = true;
                    json["message"] = "Form is incomplete";
                }
            }
            else
            {
                json["error"]   = true;
                json["message"] = "You are not authorized to continue";
            }

            return(Content(json.ToString(), "application/json"));
        }