// POST: api/servicelocation
 public IHttpActionResult Post([FromBody] ServiceLocationViewModel model)
 {
     try
     {
         var serviceLocation = new tblServiceLocation()
         {
             Name        = model.Name,
             Description = model.Description,
             Add1        = model.Add1,
             Add2        = model.Add2,
             City        = model.City,
             State       = model.State,
             Zip         = model.Zip,
             CountryId   = model.CountryId,
             Created     = DateTime.Now.ToUniversalTime(),
             IsActive    = model.IsActive,
             BusinessId  = model.BusinessId,
             TimezoneId  = model.TimezoneId
         };
         _db.tblServiceLocations.Add(serviceLocation);
         var response = _db.SaveChanges();
         if (response > 0)
         {
             return(Ok(new { status = true, data = serviceLocation }));
         }
         else
         {
             return(Ok(new { status = false, data = "There was a problem." }));
         }
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message.ToString()));
     }
 }
Пример #2
0
        public async Task <int> AddServiceLocation(ServiceLocationViewModel entity, int serviceInfoId)
        {
            var mappedEntity = _mapper.Map <ServiceLocationViewModel, ServiceLocation>(entity);

            mappedEntity.ServiceInfoId = serviceInfoId;

            return(await _serviceLocationRepository.Insert(mappedEntity));
        }
Пример #3
0
        // PUT: api/servicelocation/5
        public IHttpActionResult Put(long?id, [FromBody] ServiceLocationViewModel model)
        {
            try
            {
                if (!id.HasValue)
                {
                    return(Ok(new { status = false, data = "", message = "Please provide a valid ID." }));
                }
                else
                {
                    var serviceLocation = _db.tblServiceLocations.Find(id);
                    if (serviceLocation != null)
                    {
                        serviceLocation.Name        = model.Name;
                        serviceLocation.Description = model.Description;
                        serviceLocation.Add1        = model.Add1;
                        serviceLocation.Add2        = model.Add2;
                        serviceLocation.City        = model.City;
                        serviceLocation.State       = model.State;
                        serviceLocation.Zip         = model.Zip;
                        serviceLocation.CountryId   = model.CountryId;
                        serviceLocation.Created     = DateTime.Now.ToUniversalTime();
                        serviceLocation.IsActive    = model.IsActive;
                        serviceLocation.BusinessId  = model.BusinessId;
                        serviceLocation.TimezoneId  = model.TimezoneId;

                        _db.Entry(serviceLocation).State = EntityState.Modified;
                        var response = _db.SaveChanges();
                        if (response > 0)
                        {
                            return(Ok(new { status = true, data = serviceLocation, message = "success" }));
                        }
                        else
                        {
                            return(Ok(new { status = false, data = "", message = "There was a problem to update the data." }));
                        }
                    }
                    else
                    {
                        return(Ok(new { status = false, data = "", message = "Not a valid data to update. Please provide a valid id." }));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Ok(new { status = false, data = "", message = ex.Message.ToString() }));
            }
        }
Пример #4
0
        // POST: api/servicelocation
        public IHttpActionResult Post([FromBody] ServiceLocationViewModel model)
        {
            try
            {
                var serviceLocation = new tblServiceLocation()
                {
                    Name        = model.Name,
                    Description = model.Description,
                    Add1        = model.Add1,
                    Add2        = model.Add2,
                    City        = model.City,
                    State       = model.State,
                    Zip         = model.Zip,
                    CountryId   = model.CountryId,
                    Created     = DateTime.Now.ToUniversalTime(),
                    IsActive    = model.IsActive,
                    BusinessId  = model.BusinessId,
                    TimezoneId  = model.TimezoneId
                };

                using (var dbTrans = _db.Database.BeginTransaction())
                {
                    _db.tblServiceLocations.Add(serviceLocation);
                    var responseLocation = _db.SaveChanges();

                    var today = DateTime.Now;
                    var date  = new DateTime(today.Year, today.Month, today.Day, 8, 00, 00, DateTimeKind.Utc);
                    for (int i = 0; i < 7; i++)
                    {
                        var businessHour = new tblBusinessHour()
                        {
                            WeekDayId         = i,
                            IsStartDay        = i == 0 ? true : false,
                            IsHoliday         = false,
                            From              = date,
                            To                = date.AddHours(10),
                            IsSplit1          = false,
                            FromSplit1        = null,
                            ToSplit1          = null,
                            IsSplit2          = false,
                            FromSplit2        = null,
                            ToSplit2          = null,
                            ServiceLocationId = serviceLocation.Id
                        };
                        _db.tblBusinessHours.Add(businessHour);
                    }
                    var responseHour = _db.SaveChanges();
                    if (responseHour > 0 && responseLocation > 0)
                    {
                        dbTrans.Commit();
                        return(Ok(new { status = true, data = serviceLocation, message = "success" }));
                    }
                    else
                    {
                        dbTrans.Rollback();
                        return(Ok(new { status = false, data = "", message = "There was a problem." }));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Ok(new { status = false, data = "", message = ex.Message.ToString() }));
            }
        }
Пример #5
0
 public async Task <bool> UpdateServiceLocation(ServiceLocationViewModel entity, int locationId)
 {
     return(await _serviceLocationRepository.Update(
                _mapper.Map <ServiceLocationViewModel, ServiceLocation>(entity)));
 }
Пример #6
0
 public async Task <JsonResult> Put(ServiceLocationViewModel entity, int id)
 {
     return(Json(await _locationInfoService.UpdateServiceLocation(entity, id)));
 }
Пример #7
0
 public async Task <JsonResult> Post(ServiceLocationViewModel entity, int serviceInfoId)
 {
     return(Json(await _locationInfoService.AddServiceLocation(entity, serviceInfoId)));
 }