Exemplo n.º 1
0
        public async Task <IActionResult> Get(string id)
        {
            ISingleModelResponse <entity.Visitor> response = new SingleModelResponse <entity.Visitor>();

            try
            {
                entity.Visitor visitor = await _visitorRepository.GetVisitor(id);

                if (visitor == null)
                {
                    response.Message = "Visitor does not exist";
                    return(BadRequest(response));
                }

                response.Model   = visitor;
                response.Message = "Visitor exists in the system";
            }
            catch (Exception ex)
            {
                response.IsError      = true;
                response.ErrorMessage = "Some error occured, Please contact to administrator";
            }

            return(Ok(response));
        }
Exemplo n.º 2
0
        public async Task <entity.Visitor> EditVisitor(entity.Visitor visitor)
        {
            var result = await _visitorContext.Visitors.ReplaceOneAsync(Builders <entity.Visitor> .Filter.Eq("Id", visitor.Id), visitor);

            if (result.MatchedCount == 0)
            {
                // throw the error that employee not found.
            }

            return(visitor);
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Update([FromBody] entity.Visitor visitor)
        {
            ISingleModelResponse <entity.Visitor> response = new SingleModelResponse <entity.Visitor>();

            try
            {
                response.Model = await _visitorRepository.EditVisitor(visitor);

                response.Message = "Updated Information successfully";
            }
            catch (Exception ex)
            {
                _logger.LogInformation(entities.LoggingEvents.UpdateItem, "Exception:{0}", ex);

                response.IsError      = true;
                response.ErrorMessage = "Some Error occured, Please contact to Administrator";
                return(BadRequest(response));
            }

            return(Ok(response));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Add([FromBody] entity.Visitor visitor)
        {
            ISingleModelResponse <entity.Visitor> response = new SingleModelResponse <entity.Visitor>();

            try
            {
                response.Model = await _visitorRepository.AddVisitor(visitor);

                response.Message = "Visitor added successfully";
            }
            catch (Exception ex)
            {
                _logger.LogError(entities.LoggingEvents.InsertItem, ex, "Error while adding visitor");
                response.IsError      = true;
                response.ErrorMessage = "Could not add Visitor";

                return(BadRequest(response));
            }

            return(Ok(response));
        }
Exemplo n.º 5
0
        public async Task <entity.Visitor> AddVisitor(entity.Visitor visitor)
        {
            try
            {
                //   for(int i=0; i<5000; i++)
                //   {
                //       entity.Visitor v1 = new entity.Visitor();
                //       v1.ContactNumber = visitor.ContactNumber;
                //       v1.Country = visitor.Country;
                //       v1.CreatedBy = visitor.CreatedBy;
                //       v1.CreatedOn = visitor.CreatedOn;
                //       v1.Department = visitor.Department;
                //       v1.Email = i+ visitor.Email;
                //       v1.FirstName = visitor.FirstName+i;
                //       v1.IdentityNumber = visitor.IdentityNumber +i;
                //       v1.LastModifiedBy = visitor.LastModifiedBy;
                //       v1.LastModifiedOn = visitor.LastModifiedOn;
                //       v1.LastName = visitor.LastName+i;
                //       v1.Location = visitor.Location;
                //       v1.PhotoIdType = visitor.PhotoIdType;
                //       v1.Purpose = visitor.Purpose+i;
                //       v1.State = visitor.State;
                //       v1.ToMeet = visitor.ToMeet;
                //       v1.ZipCode = visitor.ZipCode+i;

                //       _visitorContext.Visitors.InsertOneAsync(v1);
                //   }


                await _visitorContext.Visitors.InsertOneAsync(visitor);

                return(visitor);
            }
            catch (Exception ex)
            {
                //TODO: log the error
                throw ex;
            }
        }