예제 #1
0
        public override async Task <ModulesResponse> FindModulesByClientIdAndFacilityId(ModuleFacilityIdRequest request, ServerCallContext context)
        {
            ClientFacility clientFacility = await _clientQueries.GetClientFacilityAndModulesByFacilityId(request.ClientId, request.FacilityId);

            if (clientFacility != null)
            {
                List <Modules> moduleList = new List <Modules>();
                foreach (Module m in clientFacility.modules)
                {
                    moduleList.Add(new Modules {
                        FacilityId = m.FacilityId, ModuleCode = m.ModuleCode, ModuleDescription = m.ModuleDescription
                    });
                }

                ModulesResponse response = new ModulesResponse
                {
                    ClientId     = clientFacility.ClientId,
                    ClientName   = clientFacility.ClientName,
                    FacilityId   = clientFacility.FacilityId,
                    FacilityCode = clientFacility.FacilityCode,
                    FacilityName = clientFacility.FacilityName,
                    Data         = { moduleList }
                };

                return(response);
            }

            context.Status = new Status(StatusCode.NotFound, $"Client with id {request.ClientId} and Facility with code {request.FacilityId} does not exist");
            return(null);
        }
예제 #2
0
        public ActionResult Create(ClientFloorViewModel model, IFormCollection formCollection)
        {
            SetSessionVariables();
            //ViewBag.ClientLocationID = HttpContext.Request.Query["ClientLocationID"];

            if (model != null)
            {
                model.ClientFloor.CreatedBy        = GetSessionObject().UserID;
                model.ClientFloor.Active           = true;
                model.ClientFloor.ClientID         = GetSessionObject().ClientID;
                model.ClientFloor.ClientLocationID = model.ClientFloor.ClientLocationID;// int.Parse(ViewBag.ClientLocationID);
                model.FacilityCatList = Common.GetFacilityCatList();
                List <ClientFacility> facilityList = new List <ClientFacility>();

                string DuplicateName = "";
                string OriginalName  = "";

                for (int i = 0; i < model.FacilityCatList.Count(); i++)
                {
                    for (int j = 0; j < model.FacilityCatList[i].FacilityList.Count(); j++)
                    {
                        ClientFacility faci = new ClientFacility();
                        string         ck_name_Available    = "FacilityCatList[" + i.ToString() + "].FacilityList[" + j.ToString() + "].Selected";
                        string         ck_name_IsPaid       = "FacilityCatList[" + i.ToString() + "].FacilityList[" + j.ToString() + "].IsPaidAmenity";
                        string         txt_PaidAmenityPrice = "FacilityCatList[" + i.ToString() + "].FacilityList[" + j.ToString() + "].PaidAmenityPrice";
                        var            ckAvailable          = formCollection[ck_name_Available];
                        var            ckIsPaid             = formCollection[ck_name_IsPaid];
                        var            txtPaidAmenityPrice  = formCollection[txt_PaidAmenityPrice];

                        faci.ClientID         = model.ClientFloor.ClientID;
                        faci.ClientLocationID = model.ClientFloor.ClientLocationID;
                        faci.FacilityID       = model.FacilityCatList[i].FacilityList[j].FacilityID;
                        faci.Available        = (ckAvailable.Count == 2 ? true : false);
                        faci.IsPaidAmenity    = (ckIsPaid.Count == 2 ? true : false);
                        faci.PaidAmenityPrice = (ckIsPaid.Count == 2 ? Convert.ToDouble(txtPaidAmenityPrice) : 0);
                        if (faci.Available)
                        {
                            facilityList.Add(faci);
                        }
                    }
                }

                ClientFloorRequest FloorRequest = new ClientFloorRequest();
                FloorRequest.clientFacilities = facilityList;

                string UploadRootPath      = "Upload";
                string uploadsFolder       = "\\client\\" + GetSessionObject().ClientID + "\\FloorPlanImages\\";
                string serverUploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, UploadRootPath);
                serverUploadsFolder += uploadsFolder;
                if (!Directory.Exists(serverUploadsFolder))
                {
                    Directory.CreateDirectory(serverUploadsFolder);
                }

                //RCCopy image uploader
                if (model.FloorPlanFilePath != null && model.ClientFloor.FloorName != null)
                {
                    OriginalName = model.FloorPlanFilePath.FileName;
                    string extension = Path.GetExtension(OriginalName);
                    DuplicateName = Guid.NewGuid().ToString() + extension;

                    string filePath = Path.Combine(serverUploadsFolder, DuplicateName);
                    model.FloorPlanFilePath.CopyTo(new FileStream(filePath, FileMode.Create));
                    model.ClientFloor.FloorPlanFilePath = "\\" + UploadRootPath + uploadsFolder + DuplicateName;
                }

                model.ClientFloor.FloorNumber = model.FloorNumber;
                FloorRequest.clientFloor      = model.ClientFloor;

                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(Common.Instance.ApiClientControllerName);

                    //HTTP POST ClientFloor
                    var postTask = client.PostAsJsonAsync <ClientFloorRequest>(Common.Instance.ApiClientUpdateClientFloor, FloorRequest);
                    postTask.Wait();

                    var result = postTask.Result;
                    if (result.IsSuccessStatusCode)
                    {
                        var readTask = result.Content.ReadAsAsync <bool>();
                        readTask.Wait();

                        //if(readTask.Result);
                    }
                }

                //ModelState.AddModelError(string.Empty, "Server Error. Please contact administrator.");
            }

            return(RedirectToAction("Index", new { ClientLocationID = model.ClientFloor.ClientLocationID }));
        }