Example #1
0
        public async Task <ActionResult <Advertisiment> > Create(Advertisiment value, IFormCollection Col)
        {
            List <EthinicalGroup> eths = new List <EthinicalGroup>();
            List <AdvAndEth>      adv  = new List <AdvAndEth> ();
            List <string>         exam = new List <string>();

            int i = 0;
            int j = 0;

            foreach (string key in Col.Keys)
            {
                AdvAndEth adve = new AdvAndEth();

                int values = 0;
                if (key.Contains("EthinicalGroup") && !key.Contains("value"))
                {
                    EthinicalGroup eth = await _ethinicalGroup.GetById(Col[key]);

                    values = Convert.ToInt32(Col[key + "value"]);

                    eths.Add(eth);
                    adve.GetEthinicalGroup = eth;
                    adve.Value             = values;
                    adv.Add(adve);
                }

                //if (key == "EthinicalGroup[" + i + "]")
                //{
                //    EthinicalGroup eth = await _ethinicalGroup.GetById(Col["EthinicalGroup[" + i + "]"]);
                //    values = Convert.ToInt32(Col["EthinicalGroup[" + i + "]value"]);

                //    eths.Add(eth);
                //    adve.GetEthinicalGroup = eth;
                //    adve.Value = values;
                //    adv.Add(adve);
                //    i++;


                //}
                if (key.Contains("Exam"))
                {
                    string examtype = Col[key];
                    exam.Add(examtype);
                    j++;
                }
            }
            value.Examtype        = exam;
            value.EthinicalGroups = eths;
            value.AdvAndEths      = adv;
            value.Group           = await _Group.GetById(value.GroupId.ToString());

            value.SubGroup = await _SubGroup.GetById(value.SubGroupId.ToString());

            value.Service = await _service.GetById(value.ServiceId.ToString());

            value.Category = await _category.GetById(value.CategoryId.ToString());

            value.Post = await _post.GetById(value.PostId.ToString());

            value.Edu = await _educationLavel.GetById(value.EducationId.ToString());

            _Advertisiment.Add(value);

            // it will be null
            //var testAdvertisiment = await _Advertisiment.GetById(value.);

            // If everything is ok then:
            await _uow.Commit();

            // The product will be added only after commit
            // testProduct = await _productRepository.GetById(product.Id);

            return(RedirectToAction("Index"));
        }
Example #2
0
        public async Task <ActionResult <Advertisiment> > Edit(string id, Advertisiment value, IFormCollection Col)
        {
            value.Id = ObjectId.Parse(id);
            List <EthinicalGroup> eths = new List <EthinicalGroup>();
            List <AdvAndEth>      adv  = new List <AdvAndEth>();
            List <string>         exam = new List <string>();
            int i = 0;
            int j = 0;

            foreach (string key in Col.Keys)
            {
                AdvAndEth adve = new AdvAndEth();

                int values = 0;
                if (key.Contains("EthinicalGroup") && !key.Contains("value"))
                {
                    EthinicalGroup eth = await _ethinicalGroup.GetById(Col[key]);

                    values = Convert.ToInt32(Col[key + "value"]);

                    eths.Add(eth);
                    adve.GetEthinicalGroup = eth;
                    adve.Value             = values;
                    adv.Add(adve);
                }

                //if (key == "EthinicalGroup[" + i + "]")
                //{
                //    EthinicalGroup eth = await _ethinicalGroup.GetById(Col["EthinicalGroup[" + i + "]"]);
                //    values = Convert.ToInt32(Col["EthinicalGroup[" + i + "]value"]);

                //    eths.Add(eth);
                //    adve.GetEthinicalGroup = eth;
                //    adve.Value = values;
                //    adv.Add(adve);
                //    i++;


                //}
                if (key.Contains("Exam"))
                {
                    string examtype = Col[key];
                    exam.Add(examtype);
                    j++;
                }

                // if(key["EthinicalGroup['"+i+"])
            }
            value.Examtype = exam;

            value.EthinicalGroups = eths;
            value.AdvAndEths      = adv;

            value.Edu = await _educationLavel.GetById(value.EducationId.ToString());

            value.Group = await _Group.GetById(value.GroupId.ToString());

            value.SubGroup = await _SubGroup.GetById(value.SubGroupId.ToString());

            value.Service = await _service.GetById(value.ServiceId.ToString());

            value.Category = await _category.GetById(value.CategoryId.ToString());

            value.Post = await _post.GetById(value.PostId.ToString());



            _Advertisiment.Update(value, id);

            await _uow.Commit();

            return(RedirectToAction("Index"));
        }