Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="name"></param>
        /// <param name="languageid">Lenguage</param>
        /// <param name="session">framework that establishes communication between the application and the database</param>
        /// <param name="context"></param>
        /// <returns></returns>
        public string GetLabelByName(string name, int languageid)
        {
            LabelRepository objrep = new LabelRepository(session);

            if (objrep.GetLabelByName(name, languageid) != null)
            {
                return(objrep.GetLabelByName(name, languageid));
            }
            else
            {
                return(name);
            }
        }
Exemplo n.º 2
0
        protected bool SaveImagesLabels(string[] labels, List <string> selectedFiles, int storeId)
        {
            Boolean isNewLabelExists = false;

            try
            {
                foreach (var label in labels)
                {
                    if (label.ToInt() > 0)
                    {
                        foreach (var m in selectedFiles)
                        {
                            LabelLine labelLine = new LabelLine();
                            labelLine.ItemId   = m.ToInt();
                            labelLine.ItemType = StoreConstants.Files;
                            labelLine.LabelId  = label.ToInt();
                            LabelLineRepository.Add(labelLine);
                        }
                    }
                    else
                    {
                        var existingLabel = LabelRepository.GetLabelByName(label, storeId);
                        int labelId       = 0;
                        if (existingLabel == null)
                        {
                            if (!String.IsNullOrEmpty(label))
                            {
                                var newLabel = new Label();
                                newLabel.StoreId     = storeId;
                                newLabel.Name        = label;
                                newLabel.ParentId    = 1;
                                newLabel.State       = true;
                                newLabel.Ordering    = 1;
                                newLabel.CreatedDate = DateTime.Now;
                                newLabel.UpdatedDate = DateTime.Now;
                                LabelRepository.Add(newLabel);
                                LabelRepository.Save();
                                labelId = newLabel.Id;
                            }
                        }
                        else
                        {
                            labelId = existingLabel.Id;
                        }

                        if (labelId > 0)
                        {
                            isNewLabelExists = true;
                            foreach (var m in selectedFiles)
                            {
                                var labelLine = new LabelLine();
                                labelLine.ItemId   = m.ToInt();
                                labelLine.ItemType = StoreConstants.Files;
                                labelLine.LabelId  = labelId;
                                LabelLineRepository.Add(labelLine);
                            }
                        }
                    }
                }

                try
                {
                    LabelLineRepository.Save();
                }
                catch (Exception ex)
                {
                    Logger.Error(ex, "Error is " + ex.StackTrace, storeId, labels);
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "Unable to save labels:" + ex.StackTrace);
            }
            return(isNewLabelExists);
        }