Example #1
0
        public ActionResult Deploy(BeaconDeployment model)
        {
            JsonResponse response = new JsonResponse();

            response.Message = ConstantUtil.MessageError;
            response.Status  = ConstantUtil.StatusFail;
            if (ModelState.IsValid)
            {
                try
                {
                    var beacon = _unitOfWorkAsync.Repository <Entities.Beacon>().GetByBeaconNum(model.BeaconId);

                    var beaconDeployment = new Entities.BeaconDeployment
                    {
                        AssetID     = model.AssetId,
                        CompanyID   = CurrentCompany.CompanyId,
                        BeaconID    = beacon.Id,
                        CreatedBy   = CurrentUser,
                        CreatedDate = DateTime.UtcNow,
                        Active      = false
                    };
                    _unitOfWorkAsync.Repository <Entities.BeaconDeployment>().Insert(beaconDeployment);
                    var success = _unitOfWorkAsync.SaveChanges() > 0;
                    if (success)
                    {
                        response.Message   = "Beacon deployed successfully.";
                        response.Status    = ConstantUtil.StatusOk;
                        response.ReturnUrl = Url.Action("Deployed");
                    }
                }
                catch (Exception ex)
                {
                    logging.Error(ex.ToString());
                }
            }
            return(Json(response, JsonRequestBehavior.AllowGet));
        }
Example #2
0
        public ActionResult EditDeployment(long id, Entities.BeaconDeployment beaconDeployment)
        {
            JsonResponse response = new JsonResponse();

            response.Message = ConstantUtil.MessageError;
            response.Status  = ConstantUtil.StatusFail;
            if (ModelState.IsValid)
            {
                var newBeaconDeployment = _unitOfWorkAsync.Repository <Entities.BeaconDeployment>().Find(beaconDeployment.BeaconDeploymentID);
                newBeaconDeployment.ModifiedBy   = CurrentUser;
                newBeaconDeployment.ModifiedDate = DateTime.UtcNow;
                newBeaconDeployment.CompanyID    = CurrentCompany.CompanyId;
                newBeaconDeployment.AssetID      = beaconDeployment.AssetID;
                _unitOfWorkAsync.Repository <Entities.BeaconDeployment>().Update(newBeaconDeployment);
                var success = _unitOfWorkAsync.SaveChanges() > 0;
                if (success)
                {
                    response.Message   = "BeaconDeployment updated successfully.";
                    response.Status    = ConstantUtil.StatusOk;
                    response.ReturnUrl = Url.Action("Deployed");
                }
            }
            return(Json(response, JsonRequestBehavior.AllowGet));
        }