示例#1
0
        public IHttpActionResult GetCompanyById(int id)
        {
            RedisKey cacheKey   = "company_" + id;
            string   cacheValue = null;

            if (Global._enableRedisCache)
            {
                cacheValue = RedisCacheHelper.GetValueByKey(cacheKey);
            }
            if (cacheValue == null)
            {
                CompanyModel companyModel = new CompanyModel();
                try
                {
                    CompanyModel.Format_Detail company = companyModel.GetById(id);
                    //RedisCacheHelper.SetKeyValue(cacheKey, JsonConvert.SerializeObject(company));
                    return(Content(HttpStatusCode.OK, company));
                }
                catch (CDSException cdsEx)
                {
                    return(Content(HttpStatusCode.BadRequest, CDSException.GetCDSErrorMessageByCode(cdsEx.ErrorId)));
                }
                catch (Exception ex)
                {
                    return(Content(HttpStatusCode.InternalServerError, ex));
                }
            }
            else
            {
                return(Content(HttpStatusCode.OK, JsonConvert.DeserializeObject(cacheValue)));
            }
        }
示例#2
0
        public IHttpActionResult GetMessageByFactoryId(int factoryId, [FromUri] int top = 10, [FromUri] int hours = 168, [FromUri] string order = "desc")
        {
            try
            {
                FactoryModel factoryModel          = new FactoryModel();
                int          companyId             = factoryModel.GetByIdForInternal(factoryId).CompanyId;
                CompanyModel companyModel          = new CompanyModel();
                CompanyModel.Format_Detail company = companyModel.GetById(companyId);

                var companySubscription = companyModel.GetValidSubscriptionPlanByCompanyId(companyId);
                if (companySubscription == null)
                {
                    throw new Exception("can't find valid subscription plan.");
                }

                DocumentDBHelper docDBHelpler = new DocumentDBHelper(companyId, companySubscription.CosmosDBConnectionString);
                return(Ok(docDBHelpler.GetMessageByFactoryId(factoryId, top, hours, order)));
            }
            catch (Exception ex)
            {
                StringBuilder logMessage = LogHelper.BuildExceptionMessage(ex);
                string        logAPI     = "[Get] " + Request.RequestUri.ToString();
                Global._appLogger.Error(logAPI + logMessage);

                return(Content(HttpStatusCode.InternalServerError, ex));
            }
        }
示例#3
0
        public IHttpActionResult GetMessageByEquipmentId(int equipmentId, [FromUri] int top = 10, [FromUri] int hours = 168, [FromUri] string order = "desc")
        {
            try
            {
                int companyId = Global.GetCompanyIdFromToken();
                if (!General.IsEquipmentUnderCompany(equipmentId, companyId))
                {
                    return(Unauthorized());
                }

                CompanyModel companyModel          = new CompanyModel();
                CompanyModel.Format_Detail company = companyModel.GetById(companyId);

                var companySubscription = companyModel.GetValidSubscriptionPlanByCompanyId(companyId);
                if (companySubscription == null)
                {
                    throw new Exception("can't find valid subscription plan.");
                }

                DocumentDBHelper docDBHelpler   = new DocumentDBHelper(companyId, companySubscription.CosmosDBConnectionString);
                EquipmentModels  equipmentModel = new EquipmentModels();

                return(Ok(docDBHelpler.GetMessageByEquipmentId(equipmentModel.getEquipmentById(equipmentId).EquipmentId, top, hours, order, companyId)));
            }
            catch (Exception ex)
            {
                StringBuilder logMessage = LogHelper.BuildExceptionMessage(ex);
                string        logAPI     = "[Get] " + Request.RequestUri.ToString();
                Global._appLogger.Error(logAPI + logMessage);

                return(Content(HttpStatusCode.InternalServerError, ex));
            }
        }
示例#4
0
        public IHttpActionResult GetAlarmMessageByFactoryId(int factoryId, [FromUri] int top = 10, [FromUri] int hours = 168, [FromUri] string order = "desc")
        {
            try
            {
                FactoryModels factoryModel         = new FactoryModels();
                int           companyId            = factoryModel.getFactoryById(factoryId).CompanyId;
                CompanyModel  companyModel         = new CompanyModel();
                CompanyModel.Format_Detail company = companyModel.GetById(companyId);
                var companySubscription            = companyModel.GetValidSubscriptionPlanByCompanyId(companyId);
                DocumentDBHelper docDBHelpler      = new DocumentDBHelper(companyId, companySubscription.CosmosDBConnectionString);
                return(Ok(docDBHelpler.GetAlarmMessageByFactoryId(factoryId, top, hours, order)));
            }
            catch (CDSException cdsEx)
            {
                IHttpActionResult   response;
                HttpResponseMessage responseMsg = new HttpResponseMessage(HttpStatusCode.BadRequest);
                string body = new JavaScriptSerializer().Serialize(CDSException.GetCDSErrorMessageByCode(cdsEx.ErrorId));
                responseMsg.Content = new StringContent(body, Encoding.UTF8, "application/json");
                response            = ResponseMessage(responseMsg);
                return(response);
            }
            catch (Exception ex)
            {
                StringBuilder logMessage = LogHelper.BuildExceptionMessage(ex);
                string        logAPI     = "[Get] " + Request.RequestUri.ToString();
                Global._appLogger.Error(logAPI + logMessage);

                return(Content(HttpStatusCode.InternalServerError, ex));
            }
        }
示例#5
0
        // Allow Client from AdminWeb, SuperAdminWeb and pre-defined Allow Domains
        public async Task Register(string CompanyId)
        {
            Startup._appLogger.Info("CompanyID: " + CompanyId);
            string clientOrigin = Context.Headers["Origin"];

            if (clientOrigin != null && clientOrigin.Contains("//"))
            {
                clientOrigin = clientOrigin.Substring(clientOrigin.IndexOf("//") + 2);
            }

            if (CompanyId != "0" && clientOrigin != null && (clientOrigin != Startup._adminWebURI || clientOrigin != Startup._superAdminWebURI))
            {
                Startup._appLogger.Warn(String.Format("Client Origin: {0}, Check Allow Domain ...", clientOrigin));
                try
                {
                    CompanyModel companyModel = new CompanyModel();
                    Company      company      = companyModel.GetById(int.Parse(CompanyId));
                    if (company.AllowDomain != null && company.AllowDomain != "*")
                    {
                        Startup._appLogger.Info("CompanyID: " + CompanyId + ", Allow Domain: " + company.AllowDomain);
                        if (!company.AllowDomain.Contains(clientOrigin))
                        {
                            Startup._appLogger.Warn("Unauthorized. Allow Domain (" + company.AllowDomain + "); Request Domain (" + clientOrigin + ")");
                            return;
                        }
                    }
                    Startup._appLogger.Warn("Authorized. Allow Domain (" + company.AllowDomain + "); Request Domain (" + clientOrigin + ")");
                }
                catch (Exception ex)
                {
                    Startup._appLogger.Error("Exception on Allow Domain Check: " + ex.Message + "," + ex.InnerException.Message);
                    return;
                }
            }
            await Groups.Add(Context.ConnectionId, CompanyId);

            PublishMessage(CompanyId, "{\"topic\":\"welcome\"}");
        }
示例#6
0
        public async Task <IHttpActionResult> UploadLogoFile(int id)
        {
            string logAPI = "[Put] " + Request.RequestUri.ToString();

            // Check if the request contains multipart/form-data.
            if (!Request.Content.IsMimeMultipartContent())
            {
                return(Content(HttpStatusCode.UnsupportedMediaType, HttpResponseFormat.UnsupportedMediaType()));
            }

            CompanyModel companyModel = new CompanyModel();
            //FileHelper fileHelper = new FileHelper();
            BlobStorageHelper storageHelper = new BlobStorageHelper(Global._systemStorageName, Global._systemStorageKey, Global._imageStorageContainer);
            string            root          = Path.GetTempPath();
            var provider = new MultipartFormDataStreamProvider(root);

            try
            {
                CompanyModel.Format_Detail company = companyModel.GetById(id);
            }
            catch (CDSException cdsEx)
            {
                return(Content(HttpStatusCode.BadRequest, CDSException.GetCDSErrorMessageByCode(cdsEx.ErrorId)));
            }
            catch (Exception ex)
            {
                StringBuilder logMessage = LogHelper.BuildExceptionMessage(ex);
                Global._appLogger.Error(logAPI + logMessage);

                return(Content(HttpStatusCode.InternalServerError, ex));
            }

            try
            {
                // Read the form data.
                string LogoAbsoluteUri = "", IconAbsoluteUri = "";
                await Request.Content.ReadAsMultipartAsync(provider);

                //FileData
                foreach (MultipartFileData fileData in provider.FileData)
                {
                    string fileExtension = Path.GetExtension(fileData.Headers.ContentDisposition.FileName.Replace("\"", "").ToLower());
                    if (fileExtension.Equals(".jpg", StringComparison.InvariantCultureIgnoreCase) ||
                        fileExtension.Equals(".jpeg", StringComparison.InvariantCultureIgnoreCase) ||
                        fileExtension.Equals(".png", StringComparison.InvariantCultureIgnoreCase))
                    {
                        ImageHelper imageHelper    = new ImageHelper();
                        string      uploadFilePath = String.Format("company-{0}", id);

                        LogoAbsoluteUri = imageHelper.PublishImage(fileData.LocalFileName, storageHelper, uploadFilePath, Global._companyLogoWidthHeight, Global._imageBgColor, Global._imageFormat);
                        IconAbsoluteUri = imageHelper.PublishImage(fileData.LocalFileName, storageHelper, uploadFilePath, Global._companyIconWidthHeight, Global._imageBgColor, Global._imageFormat);
                    }
                    else
                    {
                        return(Content(HttpStatusCode.BadRequest, HttpResponseFormat.Error("Unsupport File Type.")));
                    }
                }

                if (LogoAbsoluteUri.Equals(""))
                {
                    return(Content(HttpStatusCode.BadRequest, HttpResponseFormat.Error("File is empty or wrong extension name.")));
                }

                //Edit company logo path
                companyModel.UpdateLogoURL(id, LogoAbsoluteUri, IconAbsoluteUri);
                //RedisCacheHelper.DeleteCompanyCache(id);
                return(Content(HttpStatusCode.OK, HttpResponseFormat.Success(LogoAbsoluteUri)));
            }
            catch (CDSException cdsEx)
            {
                return(Content(HttpStatusCode.BadRequest, CDSException.GetCDSErrorMessageByCode(cdsEx.ErrorId)));
            }
            catch (System.Exception ex)
            {
                StringBuilder logMessage = LogHelper.BuildExceptionMessage(ex);
                Global._appLogger.Error(logAPI + logMessage);

                return(Content(HttpStatusCode.InternalServerError, ex));
            }
        }
示例#7
0
        public ActionResult New(string companyCode)
        {
            ///    private readonly UserModel userModel = UserModel.inst;
            ///

            ///    reportModel = new ReportModel();
            ///     userModel = new UserModel();
            ////   companyModel = new CompanyModel();
            ModelState.Clear();

            int id = 0;

            if (companyCode != null)
            {
                id = companyModel.GetCompanyByCode(companyCode);
                if (id == 0)
                {
                    return(RedirectToAction("Index", "Index"));

                    // zmachit kod v baze ne nashl
                    ViewBag.currentCompanySubmitted = companyCode;
                    ViewBag.currentCompany          = "";
                    id = 1;
                }
            }
            else
            {
                return(RedirectToAction("Index", "Index"));
                // esli u nas net company_code, znachit reportera nado redirect na index/company_selector
            }

            if (id > 0)
            {
                #region EC-CC Viewbag
                ViewBag.is_cc = is_cc;
                string cc_ext = "";
                if (is_cc)
                {
                    cc_ext = "_cc";
                }
                ViewBag.cc_extension = cc_ext;
                #endregion


                //    if(id == 1 ) - nado pokazat message reporteru iz psd
                //         reporter - file report no company
                ////screen - http://invis.io/QK2VGQNAW
                ////PSD - http://invis.io/a/G91HFKB8NJ4ZV


                CompanyModel model          = new CompanyModel(id);
                company      currentCompany = model.GetById(id);
                //company currentCompany = CompanyModel.inst.GetById(id);
                ViewBag.currentCompanyId = currentCompany.id;

                /*caseInformation*/

                if (reportModel.isCustomIncidentTypes(ViewBag.currentCompanyId))
                {
                    /*custom types*/
                    ViewBag.secondary_type_mandatory = reportModel.getCompanySecondaryType(ViewBag.currentCompanyId);
                    ViewBag.CustomSecondaryType      = true;
                }
                else
                {
                    /*default*/
                    ViewBag.secondary_type_mandatory = reportModel.getSecondaryTypeMandatory().Where(t => t.status_id == 2).ToList();
                    ViewBag.CustomSecondaryType      = false;
                }

                //ViewBag.currentCompanySubmitted = CompanyModel.inst.GetById(id).company_nm;
                ViewBag.currentCompanySubmitted = currentCompany.company_nm;
                ViewBag.currentCompany          = currentCompany.company_nm;
                //ViewBag.country = currentCompany.address.country.country_nm;
                ViewBag.locations   = HtmlDataHelper.MakeSelect(companyModel.Locations(id).Where(t => t.status_id == 2).ToList(), item => new HtmlDataHelper.SelectItem(item.id.ToString(), item.T("location")));
                ViewBag.managament  = companyModel.getManagamentKnow();
                ViewBag.frequencies = HtmlDataHelper.MakeSelect(companyModel.getFrequencies(), item => new HtmlDataHelper.SelectItem(item.id.ToString(), item.T("description")));
                List <country> arr = companyModel.getCountries();
                ViewBag.countries            = HtmlDataHelper.MakeSelect(arr, item => new HtmlDataHelper.SelectItem(item.id.ToString(), item.country_nm.ToString()));
                ViewBag.countriesDescription = arr;
                ViewBag.reportedOutsides     = companyModel.getReportedOutside();
                List <role_in_report> roleInReport         = db.role_in_report.ToList();
                List <SelectListItem> selectedRoleInReport = new List <SelectListItem>();
                /*put other*/
                SelectListItem temp = new SelectListItem {
                    Text = App_LocalResources.GlobalRes.Other, Value = "0", Selected = true
                };
                selectedRoleInReport.Add(temp);
                foreach (var item in roleInReport)
                {
                    SelectListItem role = new SelectListItem {
                        Text = item.role_en, Value = item.id.ToString()
                    };
                    selectedRoleInReport.Add(role);
                }
                ViewBag.selectedRoleInReport = selectedRoleInReport;
                List <anonymity> list_anon = companyModel.GetAnonymities(id, 0);
                foreach (anonymity _anon in list_anon)
                {
                    _anon.anonymity_company_en = string.Format(_anon.anonymity_company_en, currentCompany.company_nm);
                    _anon.anonymity_ds_en      = string.Format(_anon.anonymity_ds_en, currentCompany.company_nm);
                    _anon.anonymity_en         = string.Format(_anon.anonymity_en, currentCompany.company_nm);
                }
                ViewBag.anonimity = list_anon;
                /*Relationship to company*/
                List <company_relationship> relationship = reportModel.getCustomRelationshipCompany(ViewBag.currentCompanyId);
                if (relationship.Count > 0)
                {
                    //loadCustom
                    //get other
                    //company_relationship other = companyModel.getOtherRelationship();
                    //relationship.Add(other);
                    ViewBag.relationship = relationship;
                }
                else
                {
                    ViewBag.relationship = companyModel.getRelationships();
                }


                //  ViewBag.departments = HtmlDataHelper.MakeSelect(currentCompany.company_department.ToList(), item => new HtmlDataHelper.SelectItem(item.id.ToString(), item.T("department")));
                var departmentsActive = companyModel.CompanyDepartmentsActive(id).ToList();

                company_department empty = new company_department();
                empty.department_en = App_LocalResources.GlobalRes.notListed;
                empty.id            = 0;
                departmentsActive.Add(empty);
                ViewBag.departments = HtmlDataHelper.MakeSelect(departmentsActive, item => new HtmlDataHelper.SelectItem(item.id.ToString(), item.T("department")));


                ViewBag.locationsOfIncident = HtmlDataHelper.MakeSelect(companyModel.Locations(id).Where(t => t.status_id == 2).ToList(), item => new HtmlDataHelper.SelectItem(item.id.ToString(), item.T("location")));

                // ViewBag.departments2 = currentCompany.company_department.ToList();
                ViewBag.departments2 = companyModel.CompanyDepartmentsActive(id).ToList();

                ViewBag.locationsOfIncident2 = companyModel.Locations(id).Where(t => t.status_id == 2).ToList();

                ViewBag.injury_damage = companyModel.GetInjuryDamages().ToList();

                ViewBag.supervisingMediators    = companyModel.AllSupervisingMediators(id, true);    // HtmlDataHelper.MakeSelect(companyModel.AllSupervisingMediators(id, true).ToList(), item => new HtmlDataHelper.SelectItem(item.id.ToString(), item.last_nm));
                ViewBag.nonSupervisingMediators = companyModel.AllNonSupervisingMediators(id, true); // HtmlDataHelper.MakeSelect(companyModel.AllSupervisingMediators(id, true).ToList(), item => new HtmlDataHelper.SelectItem(item.id.ToString(), item.last_nm));

                // company logo
                string companyLogo = currentCompany.path_en;
                string path        = System.IO.Directory.GetCurrentDirectory();
                if (!System.IO.Directory.Exists(path + companyLogo))
                {
                    ViewBag.companylogo = companyLogo;
                }
                else
                {
                    ViewBag.companyLogo = null;
                }
                //
            }
            else
            {
                // esli u nas net company_code, znachit reportera nado redirect na index/company_selector
                return(RedirectToAction("index", "Index"));
            }

            return(View());
        }