Пример #1
0
        public async Task <IActionResult> SavePosition([FromBody] PositionModel helper)
        {
            try
            {
                Positions positions = new Positions();
                positions.OrganizationId = helper.OrganizationId;
                positions.Name           = helper.Name;

                if (!string.IsNullOrEmpty(helper.DefaultTime))
                {
                    helper.DefaultTime    = helper.DefaultTime + ":00";
                    positions.DefaultTime = DateTime.ParseExact(helper.DefaultTime, "HH:mm:ss", CultureInfo.InvariantCulture);
                }

                if (!string.IsNullOrEmpty(helper.DefaultTime2))
                {
                    helper.DefaultTime2    = helper.DefaultTime2 + ":00";
                    positions.DefaultTime2 = DateTime.ParseExact(helper.DefaultTime2, "HH:mm:ss", CultureInfo.InvariantCulture);
                }

                _context.Positions.Add(positions);
                await _context.SaveChangesAsync();

                return(Ok(helper));
            }
            catch (System.Exception ex)
            {
                return(BadRequest(new { message = "Error is" + ex.Message }));
            }
        }
Пример #2
0
        public async Task <IActionResult> SaveOrganization([FromBody] Organizations helper)
        {
            try
            {
                _context.Organizations.Add(helper);
                await _context.SaveChangesAsync();

                return(Ok(helper));
            }
            catch (System.Exception ex)
            {
                return(BadRequest(new { message = "Error is" + ex.Message }));
            }
        }
Пример #3
0
        public async Task <IActionResult> SaveEmployer([FromBody] Employees employer)
        {
            try
            {
                employer.CreatedAt = DateTime.Now;
                employer.Status    = true;
                _context.Employees.Add(employer);
                await _context.SaveChangesAsync();

                return(Ok(employer));
            }
            catch (System.Exception ex)
            {
                return(BadRequest(new { message = "Error is" + ex.Message }));
            }
        }
Пример #4
0
        public async Task <IActionResult> Update(Int32 id, [FromBody] Shifts helpers)
        {
            try
            {
                var existingHelper = await _context.Shifts.Where(x => x.Id == helpers.Id).SingleOrDefaultAsync();

                var shiftToReturn = GetShift(existingHelper);
                if (helpers == null)
                {
                    return(BadRequest());
                }
                if (helpers.EmployeeId != null)
                {
                    // For the database
                    existingHelper.EmployeeId = helpers.EmployeeId;

                    // For response
                    shiftToReturn.EmployeeId = helpers.EmployeeId;
                    var empName = _context.Employees.Where(x => x.Id == shiftToReturn.EmployeeId).Single();
                    shiftToReturn.Title = empName.FirstName + " " + empName.LastName;
                }
                else
                {
                    // For the database
                    existingHelper.IsCanceled = helpers.IsCanceled;
                    existingHelper.CanceledAt = DateTime.Now;
                    existingHelper.CanceledBy = helpers.CanceledBy;

                    // For response
                    shiftToReturn.IsCanceled = helpers.IsCanceled;
                    shiftToReturn.CanceledAt = DateTime.Now;
                    shiftToReturn.CanceledBy = helpers.CanceledBy;
                }
                await _context.SaveChangesAsync(true);

                return(Ok(shiftToReturn));
            }
            catch (System.Exception ex)
            {
                return(BadRequest(new { message = "Error is" + ex.Message }));
            }
        }