public async Task <IHttpActionResult> PutConsultantTask(int id, ConsultantTask consultantTask)
        {
            logger.Info(DateTime.Now + ":" + "Inside the PutConsultantTask IHttpActionResult in the ConsultantTasks Controller");
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != consultantTask.TaskId)
            {
                return(BadRequest());
            }

            _db.Entry(consultantTask).State = EntityState.Modified;

            try
            {
                await _db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ConsultantTaskExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #2
0
        public async Task CheckIn(string regId)
        {
            logger.Info("Inside the CheckIn Method");
            var consultant = await _consultantdb.Consultants.Where(c => c.RegID == regId).SingleOrDefaultAsync();

            if (consultant == null)
            {
                var response = new HttpResponseMessage(HttpStatusCode.NoContent)
                {
                    Content      = new StringContent(string.Format("The Registration Number do not exist")),
                    ReasonPhrase = "The Registration Number do not exist"
                };
                logger.Info("Logged Details :" + JsonConvert.SerializeObject(response));
                throw new HttpResponseException(response);
            }
            var checkin = new CheckInOut
            {
                ConsultantId    = consultant.Id,
                ConsultantRegID = consultant.RegID,
                ChekedIn        = true,
                CheckinDate     = DateTime.Now.ToString("MM-dd-yyyy"),
                CheckinTime     = DateTime.Now.ToString("hh:mm tt")
            };
            var getConsultantsId = await _consultantdb.CheckInOuts.ToListAsync();

            logger.Info("Logged Details :" + JsonConvert.SerializeObject(checkin));
            var checkedInBefore = _consultantdb.CheckInOuts.Where(c => c.CheckinDate == checkin.CheckinDate && c.ConsultantRegID == regId && c.ChekedIn == true).Count();

            if (checkedInBefore >= 1)
            {
                var response = new HttpResponseMessage(HttpStatusCode.NotAcceptable)
                {
                    Content      = new StringContent(string.Format("You have already checked in today; Have a nice day at work")),
                    ReasonPhrase = "You have already checked in today; Have a nice day at work"
                };
                logger.Info("Logged Details :" + JsonConvert.SerializeObject(response));
                throw new HttpResponseException(response);
            }
            _consultantdb.CheckInOuts.Add(checkin);
            await _consultantdb.SaveChangesAsync();

            logger.Info("Saved Successfully" + ":" + JsonConvert.SerializeObject(checkin));
            var responseSuccess = new HttpResponseMessage(HttpStatusCode.Accepted)
            {
                Content      = new StringContent(string.Format("Checkin was Successful; Welcome to work")),
                ReasonPhrase = "Checkin was Successful; Welcome to work"
            };

            logger.Info("Success Response" + ":" + JsonConvert.SerializeObject(responseSuccess));
            throw new HttpResponseException(responseSuccess);
        }
예제 #3
0
        public async Task AddTask(ConsultantTask consultantTask)
        {
            logger.Info("Inside the AddTask Method");
            _consultantDB.ConsultantTasks.Add(consultantTask);
            await _consultantDB.SaveChangesAsync();

            logger.Info("Logged Details :" + JsonConvert.SerializeObject(consultantTask));
        }
예제 #4
0
        public async Task AddConsultant(Consultant consultant)
        {
            logger.Info("Inside the AddConsultant Method");
            bool validate = (consultant.FullName != null && consultant.EmailAddress != null && consultant.MobileNo != null && consultant.DOB != null);

            if (validate)
            {
                consultant.RegID = GenerateRegID();
            }
            _consultantdb.Consultants.Add(consultant);
            await _consultantdb.SaveChangesAsync();

            logger.Info("Logged Details :" + JsonConvert.SerializeObject(consultant));
        }
        public async Task Register(Assigner assigner)
        {
            logger.Info("Inside the Register Method");
            bool validateForm = (assigner.Name != null && assigner.Position != null && assigner.Username != null);

            if (validateForm)
            {
                logger.Info("Inside the validateForm condition");
                assigner.Password = GeneratePassword();
                _consultantdb.Assigners.Add(assigner);
                await _consultantdb.SaveChangesAsync();

                logger.Info("Logged Details :" + JsonConvert.SerializeObject(assigner));
            }
        }
예제 #6
0
        public async Task <IHttpActionResult> PutConsultant(int id, Consultant consultant)
        {
            logger.Info(DateTime.Now + ":" + "Inside the PutConsultant IHttpActionResult in the Consultants Controller");
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != consultant.Id)
            {
                return(BadRequest());
            }

            //_db.Entry(consultant).State = EntityState.Modified;
            var getConsultants = _db.Consultants.Where(c => c.Id == id).SingleOrDefault();

            if (string.IsNullOrEmpty(consultant.MobileNo))
            {
                getConsultants.MobileNo = getConsultants.MobileNo;
            }
            if (!string.IsNullOrEmpty(consultant.MobileNo))
            {
                getConsultants.MobileNo = consultant.MobileNo;
            }
            if (string.IsNullOrEmpty(consultant.RegID))
            {
                getConsultants.RegID = getConsultants.RegID;
            }
            if (!string.IsNullOrEmpty(consultant.RegID))
            {
                getConsultants.RegID = consultant.RegID;
            }
            if (string.IsNullOrEmpty(consultant.FullName))
            {
                getConsultants.FullName = getConsultants.FullName;
            }
            if (!string.IsNullOrEmpty(consultant.FullName))
            {
                getConsultants.FullName = consultant.FullName;
            }
            if (string.IsNullOrEmpty(consultant.EmailAddress))
            {
                getConsultants.EmailAddress = getConsultants.EmailAddress;
            }
            if (!string.IsNullOrEmpty(consultant.EmailAddress))
            {
                getConsultants.EmailAddress = consultant.EmailAddress;
            }
            if (string.IsNullOrEmpty(consultant.DOB))
            {
                getConsultants.DOB = getConsultants.DOB;
            }
            if (!string.IsNullOrEmpty(consultant.DOB))
            {
                getConsultants.DOB = consultant.DOB;
            }
            try
            {
                await _db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ConsultantExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #7
0
        //public AssignmentImplementation(ConsultantDB consultantDB)
        //{
        //    _consultantDB = consultantDB;
        //}

        public async Task AssignTaskToConsultant(Assignment assignment, string consultantId, int consultantTaskId, int assignerId)
        {
            try
            {
                logger.Info("Inside the Assign Task To Consultant Method");
                var getConsultant = await _consultantDB.Consultants.Where(g => g.RegID == consultantId).SingleOrDefaultAsync();

                if (getConsultant == null)
                {
                    var response = new HttpResponseMessage(HttpStatusCode.NoContent)
                    {
                        Content      = new StringContent(string.Format("The Registration Number do not exist")),
                        ReasonPhrase = "The Registration Number do not exist"
                    };
                    logger.Info("Logged Details :" + JsonConvert.SerializeObject(response));
                    throw new HttpResponseException(response);
                }
                var getTask = await _consultantDB.ConsultantTasks.Where(t => t.TaskId == consultantTaskId).SingleOrDefaultAsync();

                if (getTask == null)
                {
                    var response = new HttpResponseMessage(HttpStatusCode.NoContent)
                    {
                        Content      = new StringContent(string.Format("The Task does not exist kindly add the task")),
                        ReasonPhrase = "The Task does not exist kindly add the task"
                    };
                    logger.Info("Logged Details :" + JsonConvert.SerializeObject(response));
                    throw new HttpResponseException(response);
                }
                var getAssigner = await _consultantDB.Assigners.Where(a => a.Id == assignerId).SingleOrDefaultAsync();

                if (true)
                {
                    var response = new HttpResponseMessage(HttpStatusCode.NoContent)
                    {
                        Content      = new StringContent(string.Format("Invalid Assigner Id")),
                        ReasonPhrase = "Invalid Assigner Id"
                    };
                    logger.Info("Logged Details :" + JsonConvert.SerializeObject(response));
                }

                var taskAssign = new Assignment
                {
                    AssignerName       = getAssigner.Name,
                    AssignerId         = getAssigner.Id,
                    ConsultantName     = getConsultant.FullName,
                    ConsultantId       = getConsultant.Id,
                    ConsultantTaskId   = getTask.TaskId,
                    ConsultantTaskName = getTask.TaskName,
                    RegNo        = getConsultant.RegID,
                    Status       = "Not Completed",
                    Achieved     = false,
                    DateAssigned = DateTime.Now.ToString("MM-dd-yyyy"),
                    TimeAssigned = DateTime.Now.ToString("HH:mm tt")
                };

                _consultantDB.Assignments.Add(taskAssign);
                await _consultantDB.SaveChangesAsync();

                logger.Info("Logged Details :" + JsonConvert.SerializeObject(taskAssign));
            }
            catch (DbEntityValidationException ex)
            {
                throw ex;
            }
        }