Exemplo n.º 1
0
        // Check
        public string TelModelOK(TelModel telModel)
        {
            string retStr = FieldCheckNotNullAndMinMaxLengthString(telModel.TelNumber, ServiceRes.TelNumber, 7, 20);

            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(retStr);
            }

            retStr = _BaseEnumService.TelTypeOK(telModel.TelType);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(retStr);
            }

            retStr = FieldCheckNotZeroInt(telModel.TelTVItemID, ServiceRes.TelTVItemID);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(retStr);
            }

            retStr = _BaseEnumService.DBCommandOK(telModel.DBCommand);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(retStr);
            }

            return("");
        }
Exemplo n.º 2
0
        public TelModel GetTelModelWithTelTVItemIDDB(int TelTVItemID)
        {
            TelModel telModel = (from c in db.Tels
                                 where c.TelTVItemID == TelTVItemID
                                 select new TelModel
            {
                Error = "",
                TelID = c.TelID,
                DBCommand = (DBCommandEnum)c.DBCommand,
                TelTVItemID = c.TelTVItemID,
                TelNumber = c.TelNumber,
                TelType = (TelTypeEnum)c.TelType,
                TelTypeText = "",
                LastUpdateDate_UTC = c.LastUpdateDate_UTC,
                LastUpdateContactTVItemID = c.LastUpdateContactTVItemID,
            }).FirstOrDefault <TelModel>();

            if (telModel == null)
            {
                return(ReturnError(string.Format(ServiceRes.CouldNotFind_With_Equal_, ServiceRes.Tel, ServiceRes.TelTVItemID, TelTVItemID)));
            }
            else
            {
                telModel.TelTypeText = _BaseEnumService.GetEnumText_TelTypeEnum((TelTypeEnum)telModel.TelType);
            }
            return(telModel);
        }
Exemplo n.º 3
0
        private static TelModel ToModel(DataRow row)
        {
            TelModel tel = new TelModel();

            tel.Tel_id      = (System.Int64)row["tel_id"];
            tel.TelNo       = (System.String)row["telNo"];
            tel.Hospital_id = (System.Int64)row["hospital_id"];
            return(tel);
        }
Exemplo n.º 4
0
        public static TelModel[] GetAll()
        {
            DataTable table = SqlHelper.ExecuteDataTable("select * from Tel");

            TelModel[] tel = new TelModel[table.Rows.Count];
            for (int i = 0; i < table.Rows.Count; i++)
            {
                tel[i] = ToModel(table.Rows[i]);
            }
            return(tel);
        }
Exemplo n.º 5
0
        public TelModel PostAddTelDB(TelModel telModel)
        {
            string retStr = TelModelOK(telModel);

            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(ReturnError(retStr));
            }

            ContactOK contactOK = IsContactOK();

            if (!string.IsNullOrEmpty(contactOK.Error))
            {
                return(ReturnError(contactOK.Error));
            }

            TVItemModel tvItemModelTel = _TVItemService.GetTVItemModelWithTVItemIDDB(telModel.TelTVItemID);

            if (!string.IsNullOrWhiteSpace(tvItemModelTel.Error))
            {
                return(ReturnError(tvItemModelTel.Error));
            }

            Tel telNew = new Tel();

            retStr = FillTel(telNew, telModel, contactOK);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(ReturnError(retStr));
            }

            using (TransactionScope ts = new TransactionScope())
            {
                db.Tels.Add(telNew);
                retStr = DoAddChanges();
                if (!string.IsNullOrWhiteSpace(retStr))
                {
                    return(ReturnError(retStr));
                }

                LogModel logModel = _LogService.PostAddLogForObj("Tels", telNew.TelID, LogCommandEnum.Add, telNew);
                if (!string.IsNullOrWhiteSpace(logModel.Error))
                {
                    return(ReturnError(logModel.Error));
                }

                ts.Complete();
            }
            return(GetTelModelWithTelIDDB(telNew.TelID));
        }
Exemplo n.º 6
0
        public void TelController_TelSaveJSON_Add_Good_Test()
        {
            foreach (CultureInfo culture in setupData.cultureListGood)
            {
                controllerAction = "TelSaveJSON";
                contactModel     = contactModelListGood[0];

                SetupTest(contactModel, culture, controllerAction);

                using (TransactionScope ts = new TransactionScope())
                {
                    int ContactTVItemID = contactModelListGood[0].ContactTVItemID;

                    TVItemLinkModel tvItemLinkModel = telService._TVItemLinkService.PostDeleteTVItemLinkWithFromTVItemIDDB(ContactTVItemID);

                    Assert.AreEqual("", tvItemLinkModel.Error);

                    TVItemModel tvItemModelContact = telService._TVItemService.GetTVItemModelWithTVItemIDDB(ContactTVItemID);

                    Assert.AreEqual("", tvItemModelContact.Error);

                    TelModel telModel = randomService.RandomTelModel(true);

                    Assert.AreEqual("", telModel.Error);

                    TVItemModel tvItemModelTel = telService._TVItemService.GetTVItemModelWithTVItemIDDB(telModel.TelTVItemID);

                    Assert.AreEqual("", tvItemModelTel.Error);

                    tvItemLinkModel = randomService.RandomTVItemLinkModel(tvItemModelContact, tvItemModelTel, true);

                    Assert.AreEqual("", tvItemLinkModel.Error);

                    FormCollection fc = new FormCollection();
                    fc.Add("ContactTVItemID", ContactTVItemID.ToString());
                    fc.Add("TelNumber", "374829349");
                    fc.Add("TelTVItemID", "0"); // tvItemModelTel.TVItemID.ToString());
                    fc.Add("TelType", ((int)TelTypeEnum.Personal).ToString());

                    JsonResult jsonResult = controller.TelSaveJSON(fc) as JsonResult;

                    Assert.IsNotNull(jsonResult);

                    string retStr = (string)jsonResult.Data;
                    Assert.AreEqual("", retStr);
                }
            }
        }
Exemplo n.º 7
0
        public static bool Insert(TelModel tel)
        {
            try
            {
                SqlHelper.ExecuteNonQuery(@"insert into Tel(TelNo, hospital_id)
				values(@TelNo, @hospital_id)"                ,
                                          new SqlParameter("@TelNo", tel.TelNo),
                                          new SqlParameter("@hospital_id", tel.Hospital_id)
                                          );
                return(true);
            }
            catch (SqlException)
            {
                return(false);
            }
        }
Exemplo n.º 8
0
        public void TelController__telEditList_Test()
        {
            foreach (CultureInfo culture in setupData.cultureListGood)
            {
                controllerAction = "_telEditList";
                contactModel     = contactModelListGood[0];

                SetupTest(contactModel, culture, controllerAction);

                using (TransactionScope ts = new TransactionScope())
                {
                    int ContactTVItemID = contactModelListGood[0].ContactTVItemID;

                    TVItemLinkModel tvItemLinkModel = telService._TVItemLinkService.PostDeleteTVItemLinkWithFromTVItemIDDB(ContactTVItemID);
                    Assert.AreEqual("", tvItemLinkModel.Error);

                    TVItemModel tvItemModelContact = telService._TVItemService.GetTVItemModelWithTVItemIDDB(ContactTVItemID);
                    Assert.AreEqual("", tvItemModelContact.Error);

                    TelModel telModel = randomService.RandomTelModel(true);
                    Assert.AreEqual("", telModel.Error);

                    TVItemModel tvItemModelTel = telService._TVItemService.GetTVItemModelWithTVItemIDDB(telModel.TelTVItemID);
                    Assert.AreEqual("", tvItemModelTel.Error);

                    tvItemLinkModel = randomService.RandomTVItemLinkModel(tvItemModelContact, tvItemModelTel, true);
                    Assert.AreEqual("", tvItemLinkModel.Error);

                    PartialViewResult partialViewResult = controller._telEditList(ContactTVItemID) as PartialViewResult;
                    Assert.IsNotNull(partialViewResult);

                    ContactModel contactModelRet = (ContactModel)partialViewResult.ViewBag.ContactModel;
                    Assert.AreEqual(contactModel.FirstName, contactModelRet.FirstName);
                    Assert.AreEqual(contactModel.Initial, contactModelRet.Initial);
                    Assert.AreEqual(contactModel.LastName, contactModelRet.LastName);

                    List <TelModel> telModelList = (List <TelModel>)partialViewResult.ViewBag.TelModelList;
                    Assert.AreEqual(1, telModelList.Count);
                    Assert.AreEqual(telModel.TelNumber, telModelList[0].TelNumber);
                    Assert.AreEqual(telModel.TelType, telModelList[0].TelType);

                    TelController telControllerRet = (TelController)partialViewResult.ViewBag.TelController;
                    Assert.IsNotNull(telControllerRet);
                }
            }
        }
Exemplo n.º 9
0
        // Fill
        public string FillTel(Tel tel, TelModel telModel, ContactOK contactOK)
        {
            tel.DBCommand          = (int)telModel.DBCommand;
            tel.TelTVItemID        = telModel.TelTVItemID;
            tel.TelNumber          = telModel.TelNumber;
            tel.TelType            = (int)telModel.TelType;
            tel.LastUpdateDate_UTC = DateTime.UtcNow;
            if (contactOK == null)
            {
                tel.LastUpdateContactTVItemID = 2;
            }
            else
            {
                tel.LastUpdateContactTVItemID = contactOK.ContactTVItemID;
            }

            return("");
        }
Exemplo n.º 10
0
        public static bool Update(TelModel tel)
        {
            try
            {
                SqlHelper.ExecuteNonQuery(@"update Tel set
				TelNo = @TelNo,
				hospital_id = @hospital_id
				where tel_id = @tel_id"                ,
                                          new SqlParameter("@TelNo", tel.TelNo),
                                          new SqlParameter("@hospital_id", tel.Hospital_id),
                                          new SqlParameter("@tel_id", tel.Tel_id)
                                          );
                return(true);
            }
            catch (SqlException)
            {
                return(false);
            }
        }
Exemplo n.º 11
0
        public TelModel PostDeleteTelWithTelTVItemIDDB(int TelTVItemID)
        {
            ContactOK contactOK = IsContactOK();

            if (!string.IsNullOrEmpty(contactOK.Error))
            {
                return(ReturnError(contactOK.Error));
            }

            TelModel telModelToDelete = GetTelModelWithTelTVItemIDDB(TelTVItemID);

            if (!string.IsNullOrWhiteSpace(telModelToDelete.Error))
            {
                return(ReturnError(telModelToDelete.Error));
            }

            telModelToDelete = PostDeleteTelDB(telModelToDelete.TelID);
            if (!string.IsNullOrWhiteSpace(telModelToDelete.Error))
            {
                return(ReturnError(telModelToDelete.Error));
            }

            return(ReturnError(""));
        }
Exemplo n.º 12
0
 // Helper
 public string CreateTVText(TelModel telModel)
 {
     return(telModel.TelNumber);
 }
Exemplo n.º 13
0
 public bool PhoneSil(TelModel id)
 {
     KY.KisiTelSil(id.TelId);
     return(true);
 }
Exemplo n.º 14
0
        public TelModel PostUpdateTelDB(TelModel telModel)
        {
            string retStr = TelModelOK(telModel);

            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(ReturnError(retStr));
            }

            ContactOK contactOK = IsContactOK();

            if (!string.IsNullOrEmpty(contactOK.Error))
            {
                return(ReturnError(contactOK.Error));
            }

            Tel telToUpdate = GetTelWithTelIDDB(telModel.TelID);

            if (telToUpdate == null)
            {
                return(ReturnError(string.Format(ServiceRes.CouldNotFind_ToUpdate, ServiceRes.Tel)));
            }

            retStr = FillTel(telToUpdate, telModel, contactOK);
            if (!string.IsNullOrWhiteSpace(retStr))
            {
                return(ReturnError(retStr));
            }

            using (TransactionScope ts = new TransactionScope())
            {
                retStr = DoUpdateChanges();
                if (!string.IsNullOrWhiteSpace(retStr))
                {
                    return(ReturnError(retStr));
                }

                LogModel logModel = _LogService.PostAddLogForObj("Tels", telToUpdate.TelID, LogCommandEnum.Change, telToUpdate);
                if (!string.IsNullOrWhiteSpace(logModel.Error))
                {
                    return(ReturnError(logModel.Error));
                }

                foreach (LanguageEnum Lang in LanguageListAllowable)
                {
                    if (Lang == LanguageRequest)
                    {
                        TVItemLanguageModel tvItemLanguageModelToUpdate = _TVItemService._TVItemLanguageService.GetTVItemLanguageModelWithTVItemIDAndLanguageDB(telToUpdate.TelTVItemID, Lang);
                        if (!string.IsNullOrWhiteSpace(tvItemLanguageModelToUpdate.Error))
                        {
                            return(ReturnError(tvItemLanguageModelToUpdate.Error));
                        }

                        tvItemLanguageModelToUpdate.TVText = CreateTVText(telModel);
                        if (string.IsNullOrWhiteSpace(tvItemLanguageModelToUpdate.TVText))
                        {
                            return(ReturnError(string.Format(ServiceRes._IsRequired, ServiceRes.TVText)));
                        }

                        TVItemLanguageModel tvItemLanguageModel = _TVItemService._TVItemLanguageService.PostUpdateTVItemLanguageDB(tvItemLanguageModelToUpdate);
                        if (!string.IsNullOrWhiteSpace(tvItemLanguageModel.Error))
                        {
                            return(ReturnError(tvItemLanguageModel.Error));
                        }
                    }
                }
                ts.Complete();
            }
            return(GetTelModelWithTelIDDB(telToUpdate.TelID));
        }
Exemplo n.º 15
0
        public TelModel PostDeleteTelUnderContactTVItemIDDB(FormCollection fc)
        {
            ContactOK contactOK = IsContactOK();

            if (!string.IsNullOrWhiteSpace(contactOK.Error))
            {
                return(ReturnError(contactOK.Error));
            }

            int ContactTVItemID = 0;
            int TelTVItemID     = 0;

            int.TryParse(fc["ContactTVItemID"], out ContactTVItemID);
            if (ContactTVItemID == 0)
            {
                return(ReturnError(string.Format(ServiceRes._IsRequired, ServiceRes.ContactTVItemID)));
            }

            int.TryParse(fc["TelTVItemID"], out TelTVItemID);
            if (TelTVItemID == 0)
            {
                return(ReturnError(string.Format(ServiceRes._IsRequired, ServiceRes.TelTVItemID)));
            }

            TVItemModel tvItemModelContact = _TVItemService.GetTVItemModelWithTVItemIDDB(ContactTVItemID);

            if (!string.IsNullOrWhiteSpace(tvItemModelContact.Error))
            {
                return(ReturnError(tvItemModelContact.Error));
            }

            TVItemModel tvItemModelTel = _TVItemService.GetTVItemModelWithTVItemIDDB(TelTVItemID);

            if (!string.IsNullOrWhiteSpace(tvItemModelTel.Error))
            {
                return(ReturnError(tvItemModelTel.Error));
            }

            TelModel telModel = GetTelModelWithTelTVItemIDDB(TelTVItemID);

            if (!string.IsNullOrWhiteSpace(telModel.Error))
            {
                return(ReturnError(telModel.Error));
            }

            using (TransactionScope ts = new TransactionScope())
            {
                TVItemLinkModel tvItemLinkModel = _TVItemLinkService.PostDeleteTVItemLinkWithFromTVItemIDAndToTVItemIDDB(tvItemModelContact.TVItemID, tvItemModelTel.TVItemID);
                if (!string.IsNullOrWhiteSpace(tvItemLinkModel.Error))
                {
                    return(ReturnError(tvItemLinkModel.Error));
                }

                TelModel telModelDel = PostDeleteTelDB(telModel.TelID);
                //if (!string.IsNullOrWhiteSpace(telModelDel.Error))
                //    return ReturnError(telModelDel.Error);

                ts.Complete();
            }

            return(new TelModel()
            {
                Error = ""
            });                                   // no error
        }
Exemplo n.º 16
0
        public void ContactController_ContactDeleteJSON_Test()
        {
            foreach (CultureInfo culture in setupData.cultureListGood)
            {
                controllerAction = "ContactDeleteJSON";

                SetupTest(contactModelListGood[0], culture, controllerAction);

                using (TransactionScope ts = new TransactionScope())
                {
                    // Act
                    TVItemModel tvItemModelSubsector = randomService.RandomTVItem(TVTypeEnum.Subsector);

                    Assert.AreEqual("", tvItemModelSubsector.Error);

                    TVItemModel tvItemModelMunicipality = tvItemService.PostAddChildTVItemDB(tvItemModelSubsector.TVItemID, "Unique Municipality Name", TVTypeEnum.Municipality);

                    Assert.AreEqual("", tvItemModelMunicipality.Error);

                    TVItemLinkModel tvItemLinkModelNew = new TVItemLinkModel()
                    {
                        FromTVItemID = tvItemModelMunicipality.TVItemID,
                        ToTVItemID   = contactModelListGood[0].ContactTVItemID,
                        FromTVType   = TVTypeEnum.Municipality,
                        ToTVType     = TVTypeEnum.Contact,
                        Ordinal      = 0,
                        TVLevel      = 0,
                        TVPath       = "p" + tvItemModelMunicipality.TVItemID + "p" + contactModelListGood[0].ContactTVItemID,
                    };

                    TVItemLinkModel tvItemLinkModel = tvItemLinkService.PostAddTVItemLinkDB(tvItemLinkModelNew);

                    Assert.AreEqual("", tvItemLinkModel.Error);

                    string      TelNumber      = "3873847847";
                    TVItemModel tvItemModelTel = tvItemService.PostAddChildTVItemDB(1, TelNumber, TVTypeEnum.Tel);

                    Assert.AreEqual("", tvItemModelTel.Error);

                    TelModel telModelNew = new TelModel()
                    {
                        TelNumber   = TelNumber,
                        TelType     = TelTypeEnum.Mobile,
                        TelTVItemID = tvItemModelTel.TVItemID,
                    };

                    TelModel telModel = telService.PostAddTelDB(telModelNew);

                    Assert.AreEqual("", telModel.Error);

                    tvItemLinkModelNew = new TVItemLinkModel()
                    {
                        FromTVItemID = contactModelListGood[0].ContactTVItemID,
                        ToTVItemID   = tvItemModelTel.TVItemID,
                        FromTVType   = TVTypeEnum.Contact,
                        ToTVType     = TVTypeEnum.Tel,
                        Ordinal      = 0,
                        TVLevel      = 0,
                        TVPath       = "p" + contactModelListGood[0].ContactTVItemID + "p" + tvItemModelTel.TVItemID,
                    };

                    tvItemLinkModel = tvItemLinkService.PostAddTVItemLinkDB(tvItemLinkModelNew);

                    Assert.AreEqual("", tvItemLinkModel.Error);

                    System.Web.Mvc.FormCollection fc = new System.Web.Mvc.FormCollection();
                    fc.Add("ParentTVItemID", tvItemModelMunicipality.TVItemID.ToString());
                    fc.Add("ContactTVItemID", contactModelListGood[0].ContactTVItemID.ToString());

                    JsonResult jsonResult = controller.ContactDeleteJSON(fc) as JsonResult;

                    Assert.IsNotNull(jsonResult);

                    string retStr = (string)jsonResult.Data;
                    Assert.AreEqual("", retStr);
                }
            }
        }
Exemplo n.º 17
0
        public JsonResult TelSaveJSON(FormCollection fc)
        {
            TelModel telModel = _TelService.PostAddOrModifyDB(fc);

            return(Json(telModel.Error, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 18
0
        public JsonResult TelDeleteJSON(FormCollection fc)
        {
            TelModel telModel = _TelService.PostDeleteTelUnderContactTVItemIDDB(fc);

            return(Json(telModel.Error, JsonRequestBehavior.AllowGet));
        }
        private void ContactItem(StringBuilder sbTemp, int ContactTVItemID)
        {
            ContactModel contactModel = _ContactService.GetContactModelWithContactTVItemIDDB(ContactTVItemID);

            if (string.IsNullOrWhiteSpace(contactModel.Error))
            {
                string initial     = string.IsNullOrWhiteSpace(contactModel.Initial) ? "" : $"{ contactModel.Initial}, ";
                string contactText = $"{contactModel.FirstName} {initial} {contactModel.LastName}";
                sbTemp.AppendLine($@"<tr>");
                sbTemp.AppendLine($@"<td>&nbsp;&nbsp;</td>");
                sbTemp.AppendLine($@"<td colspan=""19"">");
                sbTemp.AppendLine($@"<h4>{ contactText }</h4>");
                sbTemp.AppendLine($@"</td>");
                sbTemp.AppendLine($@"</tr>");

                List <TVItemLinkModel> tvItemLinkModelList = _TVItemLinkService.GetTVItemLinkModelListWithFromTVItemIDDB(ContactTVItemID);
                if (tvItemLinkModelList.Where(c => c.ToTVType == TVTypeEnum.Tel).Any())
                {
                    sbTemp.AppendLine($@"<tr>");
                    sbTemp.AppendLine($@"<td>&nbsp;&nbsp;</td><td>&nbsp;&nbsp;</td>");
                    sbTemp.AppendLine($@"<td colspan=""18"">");
                    foreach (TVItemLinkModel tvItemLinkModel in tvItemLinkModelList)
                    {
                        if (tvItemLinkModel.ToTVType == TVTypeEnum.Tel)
                        {
                            TelModel telModel = _TelService.GetTelModelWithTelTVItemIDDB(tvItemLinkModel.ToTVItemID);

                            sbTemp.AppendLine($@"<span style=""white-space: nowrap;"">{telModel.TelNumber} ({_BaseEnumService.GetEnumText_TelTypeEnum(telModel.TelType)})</span>");
                        }
                    }
                    sbTemp.AppendLine($@"</td>");
                    sbTemp.AppendLine($@"</tr>");
                }

                if (tvItemLinkModelList.Where(c => c.ToTVType == TVTypeEnum.Email).Any())
                {
                    sbTemp.AppendLine($@"<tr>");
                    sbTemp.AppendLine($@"<td>&nbsp;&nbsp;</td><td>&nbsp;&nbsp;</td>");
                    sbTemp.AppendLine($@"<td colspan=""18"">");
                    foreach (TVItemLinkModel tvItemLinkModel in tvItemLinkModelList)
                    {
                        if (tvItemLinkModel.ToTVType == TVTypeEnum.Email)
                        {
                            EmailModel emailModel = _EmailService.GetEmailModelWithEmailTVItemIDDB(tvItemLinkModel.ToTVItemID);

                            sbTemp.AppendLine($@"<span style=""white-space: nowrap;"">{emailModel.EmailAddress} ({_BaseEnumService.GetEnumText_EmailTypeEnum(emailModel.EmailType)})</span>");
                        }
                    }
                    sbTemp.AppendLine($@"</td>");
                    sbTemp.AppendLine($@"</tr>");
                }

                if (tvItemLinkModelList.Where(c => c.ToTVType == TVTypeEnum.Address).Any())
                {
                    sbTemp.AppendLine($@"<tr>");
                    sbTemp.AppendLine($@"<td>&nbsp;&nbsp;</td><td>&nbsp;&nbsp;</td>");
                    sbTemp.AppendLine($@"<td colspan=""18"">");
                    foreach (TVItemLinkModel tvItemLinkModel in tvItemLinkModelList)
                    {
                        if (tvItemLinkModel.ToTVType == TVTypeEnum.Address)
                        {
                            AddressModel addressModel = _AddressService.GetAddressModelWithAddressTVItemIDDB(tvItemLinkModel.ToTVItemID);

                            if (string.IsNullOrWhiteSpace(addressModel.Error))
                            {
                                string CivicAddress = "";
                                if (_TaskRunnerBaseService._BWObj.appTaskModel.Language == LanguageEnum.fr)
                                {
                                    CivicAddress = $"{addressModel.StreetNumber} {addressModel.StreetName} {_BaseEnumService.GetEnumText_StreetTypeEnum(addressModel.StreetType)} {addressModel.MunicipalityTVText} {addressModel.ProvinceTVText} {addressModel.CountryTVText} {addressModel.PostalCode}";
                                }
                                else
                                {
                                    CivicAddress = $"{addressModel.StreetNumber} {addressModel.StreetName} {_BaseEnumService.GetEnumText_StreetTypeEnum(addressModel.StreetType)} {addressModel.MunicipalityTVText} {addressModel.ProvinceTVText} {addressModel.CountryTVText} {addressModel.PostalCode}";
                                }
                                _AddressService.CreateTVText(addressModel);
                                sbTemp.AppendLine($@"<b>{ TaskRunnerServiceRes.CivicAddress }:</b>&nbsp;&nbsp;{CivicAddress}");
                            }
                        }
                    }
                    sbTemp.AppendLine($@"</td>");
                    sbTemp.AppendLine($@"</tr>");
                }

                sbTemp.AppendLine($@"<td colspan=""20"">&nbsp;</td>");
                sbTemp.AppendLine($@"</tr>");
            }
        }
Exemplo n.º 20
0
        // Post
        public TelModel PostAddOrModifyDB(FormCollection fc)
        {
            ContactOK contactOK = IsContactOK();

            if (!string.IsNullOrWhiteSpace(contactOK.Error))
            {
                return(ReturnError(contactOK.Error));
            }

            int         ContactTVItemID = 0;
            int         TelTVItemID     = 0;
            string      TelNumber       = "";
            int         TelTypeInt      = 0;
            TelTypeEnum TelType         = TelTypeEnum.Error;

            int.TryParse(fc["ContactTVItemID"], out ContactTVItemID);
            if (ContactTVItemID == 0)
            {
                return(ReturnError(string.Format(ServiceRes._IsRequired, ServiceRes.ContactTVItemID)));
            }

            int.TryParse(fc["TelTVItemID"], out TelTVItemID);
            // if 0 then want to add new TVItem else want to modify

            TelNumber = fc["TelNumber"];
            if (string.IsNullOrWhiteSpace(TelNumber))
            {
                return(ReturnError(string.Format(ServiceRes._IsRequired, ServiceRes.TelNumber)));
            }

            int.TryParse(fc["TelType"], out TelTypeInt);
            if (TelTypeInt == 0)
            {
                return(ReturnError(string.Format(ServiceRes._IsRequired, ServiceRes.TelType)));
            }

            TelType = (TelTypeEnum)TelTypeInt;

            TelModel telModel = new TelModel();

            using (TransactionScope ts = new TransactionScope())
            {
                if (TelTVItemID == 0)
                {
                    TVItemModel tvItemModelRoot = _TVItemService.GetRootTVItemModelDB();
                    if (!string.IsNullOrWhiteSpace(tvItemModelRoot.Error))
                    {
                        return(ReturnError(tvItemModelRoot.Error));
                    }

                    TVItemModel tvItemModelContact = _TVItemService.GetTVItemModelWithTVItemIDDB(ContactTVItemID);
                    if (!string.IsNullOrWhiteSpace(tvItemModelContact.Error))
                    {
                        return(ReturnError(tvItemModelContact.Error));
                    }

                    TelModel telModelNew = new TelModel()
                    {
                        DBCommand = DBCommandEnum.Original,
                        TelNumber = TelNumber,
                        TelType   = TelType,
                    };

                    string TVText = CreateTVText(telModelNew);
                    if (string.IsNullOrWhiteSpace(TVText))
                    {
                        return(ReturnError(string.Format(ServiceRes._IsRequired, ServiceRes.TVText)));
                    }

                    TVItemModel tvItemModelTel = _TVItemService.GetChildTVItemModelWithParentIDAndTVTextAndTVTypeDB(tvItemModelRoot.TVItemID, TVText, TVTypeEnum.Tel);
                    if (!string.IsNullOrWhiteSpace(tvItemModelTel.Error))
                    {
                        // Should add
                        tvItemModelTel = _TVItemService.PostAddChildTVItemDB(tvItemModelRoot.TVItemID, TVText, TVTypeEnum.Tel);
                        if (!string.IsNullOrWhiteSpace(tvItemModelTel.Error))
                        {
                            return(ReturnError(tvItemModelTel.Error));
                        }

                        telModelNew.TelTVItemID = tvItemModelTel.TVItemID;

                        telModel = PostAddTelDB(telModelNew);
                        if (!string.IsNullOrWhiteSpace(telModel.Error))
                        {
                            return(ReturnError(telModel.Error));
                        }
                    }

                    telModel = GetTelModelWithTelTVItemIDDB(tvItemModelTel.TVItemID);
                    if (!string.IsNullOrWhiteSpace(telModel.Error))
                    {
                        return(ReturnError(telModel.Error));
                    }

                    TVItemLinkModel tvItemLinkModelNew = new TVItemLinkModel()
                    {
                        DBCommand           = DBCommandEnum.Original,
                        FromTVItemID        = tvItemModelContact.TVItemID,
                        ToTVItemID          = tvItemModelTel.TVItemID,
                        FromTVType          = tvItemModelContact.TVType,
                        ToTVType            = TVTypeEnum.Tel,
                        StartDateTime_Local = DateTime.Now,
                        Ordinal             = 0,
                        TVLevel             = 0,
                        TVPath = "p" + tvItemModelContact.TVItemID + "p" + tvItemModelTel.TVItemID,
                    };

                    TVItemLinkModel tvItemLinkModel = _TVItemLinkService.GetTVItemLinkModelWithFromTVItemIDAndToTVItemIDDB(tvItemModelContact.TVItemID, tvItemModelTel.TVItemID);
                    if (!string.IsNullOrWhiteSpace(tvItemLinkModel.Error))
                    {
                        tvItemLinkModel = _TVItemLinkService.PostAddTVItemLinkDB(tvItemLinkModelNew);
                        if (!string.IsNullOrWhiteSpace(tvItemLinkModel.Error))
                        {
                            return(ReturnError(tvItemLinkModel.Error));
                        }
                    }
                }
                else
                {
                    TelModel telModelToChange = GetTelModelWithTelTVItemIDDB(TelTVItemID);
                    if (!string.IsNullOrWhiteSpace(telModelToChange.Error))
                    {
                        return(ReturnError(telModelToChange.Error));
                    }

                    telModelToChange.TelNumber = TelNumber;
                    telModelToChange.TelType   = TelType;

                    telModel = PostUpdateTelDB(telModelToChange);
                    if (!string.IsNullOrWhiteSpace(telModel.Error))
                    {
                        return(ReturnError(telModel.Error));
                    }

                    foreach (LanguageEnum Lang in LanguageListAllowable)
                    {
                        TVItemLanguageModel tvItemLanguageModel = _TVItemService._TVItemLanguageService.GetTVItemLanguageModelWithTVItemIDAndLanguageDB(telModelToChange.TelTVItemID, Lang);
                        if (!string.IsNullOrWhiteSpace(tvItemLanguageModel.Error))
                        {
                            return(ReturnError(tvItemLanguageModel.Error));
                        }

                        tvItemLanguageModel.TVText = CreateTVText(telModelToChange);

                        tvItemLanguageModel = _TVItemService._TVItemLanguageService.PostUpdateTVItemLanguageDB(tvItemLanguageModel);
                        if (!string.IsNullOrWhiteSpace(tvItemLanguageModel.Error))
                        {
                            return(ReturnError(tvItemLanguageModel.Error));
                        }
                    }
                }

                ts.Complete();
            }

            return(telModel);
        }