示例#1
0
        public IHttpActionResult PutCompany(int id, Company company)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != company.CompanyId)
            {
                return(BadRequest());
            }

            db.Entry(company).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CompanyExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
示例#2
0
        public IHttpActionResult PutMobileDevice(int id, MobileDevice mobileDevice)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != mobileDevice.MobileDeviceId)
            {
                return(BadRequest());
            }

            db.Entry(mobileDevice).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MobileDeviceExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        //public bool Update(ProductFamily prodFam)
        //{
        //    Context.Entry(prodFam).State = EntityState.Modified;
        //    Context.ProductFamilys.Attach(prodFam);
        //    Context.SaveChanges();
        //    return true;
        //}

        public bool Delete(int id)
        {
            var prodFam = _context.ProductFamilys.FirstOrDefault(x => x.Id == id);

            if (prodFam != null)
            {
                _context.Entry(prodFam).State = EntityState.Modified;
                _context.ProductFamilys.Remove(prodFam);
                _context.SaveChanges();

                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#4
0
        public IHttpActionResult PostLicense([FromBody] LicenseRequest request)
        {
            logger.Debug("PostLicense(LicenseRequest) entered ...");

            try
            {
                // Validate Company PIN format, if invalid return an error.
                if (request.CompanyPIN.Length != 8)
                {
                    logger.InfoFormat("PIN is incorrect length : {0}, should be 8 characters", request.CompanyPIN.Length);

                    return(Ok(new LicenseResponse()
                    {
                        Error = "PIN must be 8 digits",
                        Result = (int)LicenceResultCode.PinIncorrectLength
                    }));
                }

                // Attempt to find Company from the PIN.
                Company company = db.Companies.FirstOrDefault(c => c.Pin == request.CompanyPIN);

                // If not found return an error.
                if (company == null)
                {
                    logger.InfoFormat("Failed to find Company with PIN : {0}", request.CompanyPIN);

                    return(Ok(new LicenseResponse()
                    {
                        Error = "PIN is invalid",
                        Result = (int)LicenceResultCode.PinNotFound
                    }));
                }

                // Check if already listed as a device.
                MobileDevice device = db.MobileDevices.FirstOrDefault(d => d.SerialNo == request.SerialNo);

                // If the device exists return error showing already registered
                if (device != null)
                {
                    logger.InfoFormat("Device with Serial # : {0} already registered", request.SerialNo);

                    return(Ok(new LicenseResponse()
                    {
                        Error = "Device already registered",
                        Result = (int)LicenceResultCode.DeviceAlreadyRegistered
                    }));
                }

                // Create new device.
                device = new MobileDevice()
                {
                    Company   = company,
                    SerialNo  = request.SerialNo,
                    Created   = DateTime.Now,
                    CompanyId = company.CompanyId,
                };

                // Add to the collection of Mobile Devices ...
                device = db.MobileDevices.Add(device);
                db.SaveChanges();

                logger.DebugFormat("New device with Id : {0} created", device.MobileDeviceId);

                // Send email ...
                int numberOfDevices = db.MobileDevices.Count(d => d.CompanyId == device.MobileDeviceId);
                MailUtilities.SendEmail(numberOfDevices, device, "licensed");

                // Return configuration.
                return(Ok(new LicenseResponse()
                {
                    Result = (int)LicenceResultCode.Success,
                    DeviceNo = device.MobileDeviceId,
                    Url = device.Company.ColossusMobileUrl,
                    ConsignorName = device.Company.ConsignorName,
                    ConsignorAdd1 = device.Company.ConsignorAdd1,
                    ConsignorAdd2 = device.Company.ConsignorAdd2,
                    ConsignorAdd3 = device.Company.ConsignorAdd3,
                    Error = string.Empty
                }));
            }
            catch (Exception ex)
            {
                logger.Error("Error licensing device", ex);

                return(Ok(new LicenseResponse()
                {
                    Result = (int)LicenceResultCode.Unknown,
                    Error = "Unknown Error",
                    Url = string.Empty
                }));
            }
            finally
            {
                logger.Debug("PostLicense(LicenseRequest) exited");
            }
        }
示例#5
0
 public bool Save()
 {
     _dbContext.SaveChanges();
     return(true);
 }