public IActionResult GetAll()
 {
     try
     {
         IEnumerable <SM.Currency> cur = S.ServiceLocator.Instance.CurrencyService.Get();
         return(ApiControllerHelper.SendOk(this, new ApiResult <SM.Currency>(HttpStatusCode.OK, null, cur), true));
     }
     catch (Exception ex)
     {
         return(ApiControllerHelper.SendError(this, ex));
     }
 }
Ejemplo n.º 2
0
        public IActionResult SearchODesc([FromQuery] int page, [FromQuery] string search)
        {
            try
            {
                if (page < 1)
                {
                    throw new DataException("Page Number must be at least 1 (" + where + ") (ST)");
                }
                if (search.Length == 0)
                {
                    throw new DataException("Search String can't be BLANK (" + where + ") (ST)");
                }

                int       jump, records, maxpages = 1;
                Code_Mstr cdm = S.ServiceLocator.Instance.CodeMstrService.Get(new Code_Mstr("CONFIGURATION", "JUMP_OBJECT", ""));
                if (!int.TryParse(cdm.Code_Desc, out jump))
                {
                    jump = 50;
                }

                records = S.ServiceLocator.Instance.GeneralTypeService.SearchTextCnt(search);
                IEnumerable <GenObjectSearch> objs = null;
                if (records > 0)
                {
                    if (records > jump)
                    {
                        maxpages = records / jump;
                        if (records % jump > 0)
                        {
                            maxpages += 1;
                        }
                    }

                    if (page <= maxpages)
                    {
                        objs = S.ServiceLocator.Instance.GeneralTypeService.SearchText(page, jump, search);
                    }
                    if (objs != null && objs.OfType <GenObjectSearch>().Count() == 0)
                    {
                        objs = null;
                    }
                }
                ObjectDTO odto = new ObjectDTO(records, maxpages, page, jump, objs);

                return(ApiControllerHelper.SendOk(this, new ApiResult <ObjectDTO>(HttpStatusCode.OK, null, odto), true));
            }
            catch (Exception ex)
            {
                return(ApiControllerHelper.SendError(this, ex));
            }
        }
Ejemplo n.º 3
0
 public IActionResult ReactivateUser(int id)
 {
     try
     {
         if (id < 1)
         {
             throw new IndexOutOfRangeException("ID must be greater than 0 (" + where + ") (REACT)");
         }
         return(ApiControllerHelper.SendOk(this, new ApiResult <bool>(HttpStatusCode.OK, null, S.ServiceLocator.Instance.usersService.ReactivateUser(id)), true));
     }
     catch (Exception ex)
     {
         return(ApiControllerHelper.SendError(this, ex));
     }
 }
Ejemplo n.º 4
0
        public IActionResult Upd(int id, [FromBody] user_upd uupd)
        {
            try
            {
                if (id < 1)
                {
                    throw new IndexOutOfRangeException("ID must be greater than 0 (" + where + ") (UPD)");
                }

                if (uupd.FirstName == uupd.LastName)
                {
                    ModelState.AddModelError("LastName", "The last name cannot be the same as the first name.");
                }

                //if (uupd.Status > 1) throw new DataException("Wrong USer Status");

                // get user to get all dtata enad mod only need dtat to update and pass user object
                SM.User u = S.ServiceLocator.Instance.usersService.Get(id);

                if (u is null)
                {
                    throw new AuthenticationException("Record not found for update (" + id.ToString() + ") (" + where + ") (RESET)");
                }


                // if email orign VS emailupd <> then check email unique
                //if (u.Email != uupd.Email)
                //{
                //    bool EmailOK = S.ServiceLocator.Instance.usersService.EmailIsUsed(uupd.Email);
                //    if (EmailOK) throw new ValidationException("Email already used :" + uupd.Email);
                //}

                u.Id        = id;
                u.FirstName = uupd.FirstName;
                u.LastName  = uupd.LastName;
                u.Status    = uupd.Status;
                u.Avatar    = uupd.Avatar;

                bool UpdOk = S.ServiceLocator.Instance.usersService.Upd(id, u);;

                return(ApiControllerHelper.SendOk(this, new ApiResult <bool>(HttpStatusCode.OK, null, UpdOk), HttpStatusCode.OK));
            }

            catch (Exception ex)
            {
                return(ApiControllerHelper.SendError(this, ex));
            }
        }
Ejemplo n.º 5
0
        public IActionResult GetPage(int page)
        {
            try
            {
                if (page < 1)
                {
                    throw new DataException("Page Number must be at least 1 (" + where + ") (GETPAGE)");
                }
                int       jump, records, maxpages = 1;
                Code_Mstr cdm = S.ServiceLocator.Instance.CodeMstrService.Get(new Code_Mstr("CONFIGURATION", "JUMP_MUSIC", ""));
                if (cdm is null)
                {
                    jump = 50;
                }
                else if (!int.TryParse(cdm.Code_Desc, out jump))
                {
                    jump = 50;
                }

                records = S.ServiceLocator.Instance.GeneralTypeService.IsUsed(1);
                IEnumerable <SM.Music> mus = null;
                if (records > 0)
                {
                    if (records > jump)
                    {
                        maxpages = records / jump;
                        if (records % jump > 0)
                        {
                            maxpages += 1;
                        }
                    }

                    // int pages = S.ServiceLocator.Instance.MusicService.GetPageCount(jump);
                    if (page <= maxpages)
                    {
                        mus = S.ServiceLocator.Instance.MusicService.GetPage(page, jump);
                    }
                    if (mus != null && mus.OfType <SM.Music>().Count() == 0)
                    {
                        mus = null;
                    }
                }

                MusicDTO mdto = new MusicDTO(records, maxpages, page, jump, mus);
                return(ApiControllerHelper.SendOk(this, new ApiResult <MusicDTO>(HttpStatusCode.OK, null, mdto), true));
            }
            catch (Exception ex) { return(ApiControllerHelper.SendError(this, ex)); }
        }
Ejemplo n.º 6
0
 public IActionResult Used([FromRoute] string iso)
 {
     try
     {
         if (iso.Length != 2)
         {
             throw new IndexOutOfRangeException("Country must be 2 digits (" + where + ") (GET)");
         }
         int CtryCnt = S.ServiceLocator.Instance.CountryService.IsUsed(iso);
         return(ApiControllerHelper.SendOk(this, new ApiResult <int>(HttpStatusCode.OK, null, CtryCnt), HttpStatusCode.OK));
     }
     catch (Exception ex)
     {
         return(ApiControllerHelper.SendError(this, ex));
     }
 }
 public IActionResult Get([FromRoute] string curr)
 {
     try
     {
         if (curr.Length != 3)
         {
             throw new IndexOutOfRangeException("Currency must be 3 digits (" + where + ") (GET)");
         }
         SM.Currency cur = S.ServiceLocator.Instance.CurrencyService.Get(curr);
         return(ApiControllerHelper.SendOk(this, new ApiResult <SM.Currency>(HttpStatusCode.OK, null, cur), true));
     }
     catch (Exception ex)
     {
         return(ApiControllerHelper.SendError(this, ex));
     }
 }
 public IActionResult Del(int id)
 {
     try
     {
         if (id < 1)
         {
             throw new IndexOutOfRangeException("ID must be greater than 0 (" + where + ") (DEL)");
         }
         bool DelOk = S.ServiceLocator.Instance.Currency_ExchangeService.Del(id);
         return(ApiControllerHelper.SendOk(this, new ApiResult <bool>(HttpStatusCode.OK, null, DelOk), HttpStatusCode.OK));
     }
     catch (Exception ex)
     {
         return(ApiControllerHelper.SendError(this, ex));
     }
 }
Ejemplo n.º 9
0
 public IActionResult Used(int id)
 {
     try
     {
         if (id < 1)
         {
             throw new IndexOutOfRangeException("ID must be greater than 0 (" + where + ") (USED)");
         }
         int GenTypeCnt = S.ServiceLocator.Instance.GeneralTypeService.IsUsed(id);
         return(ApiControllerHelper.SendOk(this, new ApiResult <int>(HttpStatusCode.OK, null, GenTypeCnt), HttpStatusCode.OK));
     }
     catch (Exception ex)
     {
         return(ApiControllerHelper.SendError(this, ex));
     }
 }
Ejemplo n.º 10
0
 public IActionResult Used([FromRoute] string curr)
 {
     try
     {
         if (curr.Length != 3)
         {
             throw new IndexOutOfRangeException("Currency must be 3 digits (" + where + ") (USED)");
         }
         int CurrCnt = S.ServiceLocator.Instance.CurrencyService.CurrencyIsUsed(curr);
         return(ApiControllerHelper.SendOk(this, new ApiResult <int>(HttpStatusCode.OK, null, CurrCnt), HttpStatusCode.OK));
     }
     catch (Exception ex)
     {
         return(ApiControllerHelper.SendError(this, ex));
     }
 }
Ejemplo n.º 11
0
 public IActionResult Del([FromRoute] string curr)
 {
     try
     {
         if (curr.Length != 3)
         {
             throw new IndexOutOfRangeException("Currency must be 3 digits (" + where + ") (DEL)");
         }
         bool DelOk = S.ServiceLocator.Instance.CurrencyService.Del(curr);
         return(ApiControllerHelper.SendOk(this, new ApiResult <bool>(HttpStatusCode.OK, null, DelOk), HttpStatusCode.OK));
     }
     catch (Exception ex)
     {
         return(ApiControllerHelper.SendError(this, ex));
     }
 }
Ejemplo n.º 12
0
 public IActionResult Get(int id)
 {
     try
     {
         if (id < 1)
         {
             throw new IndexOutOfRangeException("ID must be greater than 0 (" + where + ") (GET)");
         }
         SM.GeneralType gt = S.ServiceLocator.Instance.GeneralTypeService.Get(id);
         return(ApiControllerHelper.SendOk(this, new ApiResult <SM.GeneralType>(HttpStatusCode.OK, null, gt), true));
     }
     catch (Exception ex)
     {
         return(ApiControllerHelper.SendError(this, ex));
     }
 }
Ejemplo n.º 13
0
 public IActionResult Login2([FromBody] LoginForm2 l)
 {
     try
     {
         string testpasswd = _cryptoService.Decrypter(Convert.FromBase64String(l.Passwd));
         User   u          = _clientService.LoginNRN(l.NatRegNbr, Base64.Base64Decode(l.Passwd));
         if (u is not null)
         {
             u.Token = _tokenService.GenerateToken(u);
         }
         return(ApiControllerHelper.SendOk(this, new ApiResult <User>(HttpStatusCode.OK, null, u), true));
     }
     catch (Exception ex)
     {
         return(ApiControllerHelper.SendError(this, ex));
     }
 }
Ejemplo n.º 14
0
        public IActionResult Get([FromRoute] String iso)
        {
            try
            {
                if (iso.Length != 2)
                {
                    throw new IndexOutOfRangeException("Country must be 2 digits (" + where + ") (GET)");
                }

                SM.Country ctry = S.ServiceLocator.Instance.CountryService.Get(iso);
                return(ApiControllerHelper.SendOk(this, new ApiResult <SM.Country>(HttpStatusCode.OK, null, ctry), true));
            }
            catch (Exception ex)
            {
                return(ApiControllerHelper.SendError(this, ex));
            }
        }
Ejemplo n.º 15
0
 public IActionResult Upd(int id, [FromBody] MusicAPI mus)
 {
     try
     {
         if (mus is null)
         {
             throw new ArgumentNullException("Music Object Empty (" + where + ") (UPD)");
         }
         SM.Music musa = new SM.Music(id
                                      , mus.Band, mus.Title, mus.YEAR, mus.TRACKS, mus.NbCDs, mus.NbDvds, mus.NbLps, mus.MTypeId, mus.FormatId, mus.SerialNbr, mus.Ctry,
                                      "", "",
                                      mus.Price, mus.Curr, mus.ShopId, "", mus.Date, 1, mus.Signed, mus.SignedBy, mus.EAN, mus.EAN_EXT, mus.Comment1, mus.Comment2, mus.Onwed);
         bool UpdOk = S.ServiceLocator.Instance.MusicService.Upd(musa);
         return(ApiControllerHelper.SendOk(this, new ApiResult <bool>(HttpStatusCode.OK, null, UpdOk), HttpStatusCode.OK));
     }
     catch (Exception ex) { return(ApiControllerHelper.SendError(this, ex)); }
 }
Ejemplo n.º 16
0
        public IActionResult Login([FromBody] Login l)
        {
            try
            {
                SM.User u = S.ServiceLocator.Instance.usersService.Login(l.Email, Base64.Base64Decode(l.Passwd));

                if (u is null)
                {
                    throw new AuthenticationException("Wrong Login/passwd (" + where + ") (LOGIN)");
                }

                //return Ok(new ApiResult<JWT_Bearer>(HttpStatusCode.OK, null, GenToken(u)));
                return(ApiControllerHelper.SendOk(this, new ApiResult <JWT_Bearer>(HttpStatusCode.OK, null, GenToken(u)), true));
            }
            catch (Exception ex)
            {
                return(ApiControllerHelper.SendError(this, ex));
            }
        }
Ejemplo n.º 17
0
 public IActionResult Upd([FromRoute] int userId, [FromRoute] int id, [FromBody] TimeLineUpdForm tl)
 {
     try
     {
         if (tl is null)
         {
             throw new ArgumentNullException("TimeLine Object Empty (UPD)");
         }
         TimeLine tlo = new TimeLine()
         {
             Id = id, UserId = tl.UserId, RestaurantId = tl.RestaurantId, DinerDate = tl.DinerDate, NbrGuests = tl.NbrGuests
         };
         bool UpdOk = _clientService.Upd(id, tlo);
         return(ApiControllerHelper.SendOk(this, new ApiResult <bool>(HttpStatusCode.OK, null, UpdOk), true));
     }
     catch (Exception ex)
     {
         return(ApiControllerHelper.SendError(this, ex));
     }
 }
Ejemplo n.º 18
0
 public IActionResult Upd([FromBody] CountryForm ctry)
 {
     try
     {
         if (ctry is null)
         {
             throw new ArgumentNullException("Country Empty (UPD)");
         }
         Country ctryo = new Country()
         {
             ISO = ctry.ISO, Ctry = ctry.Ctry, IsEU = ctry.IsEU
         };
         bool UpdOk = _clientService.Upd(ctryo);
         return(ApiControllerHelper.SendOk(this, new ApiResult <bool>(HttpStatusCode.OK, null, UpdOk), true));
     }
     catch (Exception ex)
     {
         return(ApiControllerHelper.SendError(this, ex));
     }
 }
Ejemplo n.º 19
0
 public IActionResult Upd(int id, [FromBody] RestaurantFormUpd resto)
 {
     try
     {
         if (resto is null)
         {
             throw new ArgumentNullException("Restaurant Object Empty (UPD)");
         }
         Restaurant restoo = new Restaurant()
         {
             Id = id, VAT = resto.VAT, Name = resto.Name, Address1 = resto.Address1, Address2 = resto.Address2, Zip = resto.Zip, City = resto.City, Country = resto.Country, Email = resto.Email, Closed = resto.Closed
         };
         bool UpdOk = _clientService.Upd(restoo);
         return(ApiControllerHelper.SendOk(this, new ApiResult <bool>(HttpStatusCode.OK, null, UpdOk), true));
     }
     catch (Exception ex)
     {
         return(ApiControllerHelper.SendError(this, ex));
     }
 }
Ejemplo n.º 20
0
 //[AuthRequired]
 public IActionResult UpdPersonal(int id, [FromBody] UserUpdLightForm u)
 {
     try
     {
         if (u is null)
         {
             throw new ArgumentNullException("User Object Empty (UPD)");
         }
         User uo = new User()
         {
             Id = id, Email = u.Email, NatRegNbr = u.NatRegNbr, FirstName = u.FirstName, LastName = u.LastName
         };
         bool UpdOk = _clientService.Upd(uo);
         return(ApiControllerHelper.SendOk(this, new ApiResult <bool>(HttpStatusCode.OK, null, UpdOk), true));
     }
     catch (Exception ex)
     {
         return(ApiControllerHelper.SendError(this, ex));
     }
 }
Ejemplo n.º 21
0
        public IActionResult Add([FromBody] user_add uadd)
        {
            try
            {
                if (uadd.FirstName == uadd.LastName)
                {
                    throw new ValidationException("The last name cannot be the same as the first name. (" + where + ") (RESET)");
                }

                if (uadd.Email.Length == 0)
                {
                    throw new ValidationException("Email empty");
                }

                // checkif email is not taken
                bool EmailOK = S.ServiceLocator.Instance.usersService.EmailIsUsed(uadd.Email);
                if (EmailOK)
                {
                    throw new ValidationException("Email already used :" + uadd.Email);
                }

                SM.User u = new SM.User();
                u.FirstName    = uadd.FirstName;
                u.LastName     = uadd.LastName;
                u.Email        = uadd.Email;
                u.Passwd       = Base64.Base64Decode(uadd.Passwd);
                u.SecretAnswer = Base64.Base64Decode(uadd.SecretAnswer);
                u.Avatar       = uadd.Avatar;

                u              = S.ServiceLocator.Instance.usersService.Add(u);
                u.Passwd       = "";  /* put passwd BLANK */
                u.SecretAnswer = "";  /* put Secret BLANK */

                return(ApiControllerHelper.SendOk(this, new ApiResult <SM.User>(HttpStatusCode.OK, null, u), true));
            }

            catch (Exception ex)
            {
                return(ApiControllerHelper.SendError(this, ex));
            }
        }
 public IActionResult Add([FromBody] MusicType mt)
 {
     try
     {
         if (mt is null)
         {
             throw new ArgumentNullException("Music Type Object Empty (" + where + ") (ADD)");
         }
         if (mt.Name.Length == 0)
         {
             throw new DataException("Music Type NAme can't be BLANK (" + where + ") (ADD)");
         }
         SM.MusicType mto = new SM.MusicType(0, mt.Name);
         mto = S.ServiceLocator.Instance.MusicTypeService.Add(mto);
         return(ApiControllerHelper.SendOk(this, new ApiResult <SM.MusicType>(HttpStatusCode.OK, null, mto), true));
     }
     catch (Exception ex)
     {
         return(ApiControllerHelper.SendError(this, ex));
     }
 }
Ejemplo n.º 23
0
        public IActionResult Get(int id)
        {
            try
            {
                if (id < 1)
                {
                    throw new IndexOutOfRangeException("ID must be greater than 0 (" + where + ") (GET)");
                }
                SM.Music mus = S.ServiceLocator.Instance.MusicService.Get(id);

                // OBJECT2 LIST SHOP

                // OBJECT3 LIST MUSIC FORMAT

                // ...

                // creare un object avec totues les auters object.

                return(ApiControllerHelper.SendOk(this, new ApiResult <SM.Music>(HttpStatusCode.OK, null, mus), true));
            }
            catch (Exception ex) { return(ApiControllerHelper.SendError(this, ex)); }
        }
Ejemplo n.º 24
0
        public IActionResult Add([FromBody] Country ctry)
        {
            try
            {
                if (ctry is null)
                {
                    throw new ArgumentNullException("Currency Exchange Object Empty (" + where + ") (ADD)");
                }
                if (ctry.ISO.Length != 2)
                {
                    throw new IndexOutOfRangeException("Country must be 2 digits (" + where + ") (ADD)");
                }

                SM.Country ctryo = new SM.Country(ctry.ISO, ctry.Ctry, ctry.IsEU);
                S.ServiceLocator.Instance.CountryService.Add(ctryo);
                return(ApiControllerHelper.SendOk(this, new ApiResult <SM.Country>(HttpStatusCode.OK, null, ctryo), true));
            }
            catch (Exception ex)
            {
                return(ApiControllerHelper.SendError(this, ex));
            }
        }
Ejemplo n.º 25
0
        public IActionResult Add([FromBody] Shop_upd sadd)
        {
            try
            {
                if (sadd is null)
                {
                    throw new ArgumentNullException("Shop Add Object Empty (" + where + ") (ADD)");
                }
                if (sadd.Name.Length == 0)
                {
                    throw new DataException("Shop Name can't be BLANK (" + where + ") (ADD)");
                }

                //if (!ModelState.IsValid) throw new ValidationException("Model is not meeting requirement");
                SM.Shop s = new SM.Shop(0, sadd.Name, sadd.Address1, sadd.Address2, sadd.ZIP, sadd.City, sadd.Country, sadd.Phone, sadd.Email, sadd.WebSite, sadd.LocalisationURL, sadd.Closed);
                s = S.ServiceLocator.Instance.shopService.Add(s);
                return(ApiControllerHelper.SendOk(this, new ApiResult <SM.Shop>(HttpStatusCode.OK, null, s), true));
            }
            catch (Exception ex)
            {
                return(ApiControllerHelper.SendError(this, ex));
            }
        }
 public SectorSendMessageStatisticController(DbContext context, ILogService logService)
     : base(context, logService)
 {
     this.apiControllerHelper = new ApiControllerHelper(context, logService);
 }
Ejemplo n.º 27
0
 public DepartmentUserController(DbContext context, ILogService logService)
     : base(context, logService)
 {
     this.apiControllerHelper = new ApiControllerHelper(context, logService);
 }
Ejemplo n.º 28
0
 public DepartmentManagerController(ISystemParameters systemParameters, DbContext context, ILogService logService)
     : base(context, logService)
 {
     this.apiControllerHelper = new ApiControllerHelper(context, logService);
     this.tradeService        = new TradeService(new UnitOfWork(context), logService);
 }