public async Task <IActionResult> CreateEstablishment([FromBody] ViewModels.AdoxioEstablishment item)
        {
            // create a new establishment.
            var adoxioEstablishment = new Adoxio_establishment();

            // create a DataServiceCollection to add the record
            var EstablishmentCollection = new DataServiceCollection <Adoxio_establishment>(_system);

            EstablishmentCollection.Add(adoxioEstablishment);

            adoxioEstablishment.CopyValues(item);

            // PostOnlySetProperties is used so that settings such as owner will get set properly by the dynamics server.

            DataServiceResponse dsr = await _system.SaveChangesAsync(SaveChangesOptions.PostOnlySetProperties | SaveChangesOptions.BatchWithIndependentOperations);

            foreach (OperationResponse operationResult in dsr)
            {
                if (operationResult.StatusCode == 500) // error
                {
                    return(StatusCode(500, operationResult.Error.Message));
                }
            }
            ViewModels.AdoxioEstablishment result = adoxioEstablishment.ToViewModel();
            result.id = ((Guid)dsr.GetAssignedId()).ToString();

            return(Json(result));
        }
        public async Task <IActionResult> DeleteEstablishment(string id)
        {
            // get the establishment.
            Guid adoxio_establishmetid = new Guid(id);

            try
            {
                Adoxio_establishment adoxioLegalEntity = await _system.Adoxio_establishments.ByKey(adoxio_establishmetid).GetValueAsync();

                _system.DeleteObject(adoxioLegalEntity);
                DataServiceResponse dsr = await _system.SaveChangesAsync();

                foreach (OperationResponse result in dsr)
                {
                    if (result.StatusCode == 500) // error
                    {
                        return(StatusCode(500, result.Error.Message));
                    }
                }
            }
            catch (Microsoft.OData.Client.DataServiceQueryException dsqe)
            {
                return(new NotFoundResult());
            }
            return(NoContent()); // 204
        }
        public async Task <IActionResult> UpdateEstablishment([FromBody] ViewModels.AdoxioEstablishment item, string id)
        {
            if (id != item.id)
            {
                return(BadRequest());
            }
            // get the establishment.
            Guid adoxio_establishmetid = new Guid(id);
            DataServiceCollection <Interfaces.Microsoft.Dynamics.CRM.Adoxio_establishment> AccountCollection = new DataServiceCollection <Interfaces.Microsoft.Dynamics.CRM.Adoxio_establishment>(_system);

            Adoxio_establishment adoxioEstablishment = await _system.Adoxio_establishments.ByKey(adoxio_establishmetid).GetValueAsync();

            _system.UpdateObject(adoxioEstablishment);
            // copy values over from the data provided
            adoxioEstablishment.CopyValues(item);


            // PostOnlySetProperties is used so that settings such as owner will get set properly by the dynamics server.

            DataServiceResponse dsr = await _system.SaveChangesAsync(SaveChangesOptions.PostOnlySetProperties | SaveChangesOptions.BatchWithIndependentOperations);

            foreach (OperationResponse result in dsr)
            {
                if (result.StatusCode == 500) // error
                {
                    return(StatusCode(500, result.Error.Message));
                }
            }
            return(Json(adoxioEstablishment.ToViewModel()));
        }
Example #4
0
 /// <summary>
 /// Copy values from a Dynamics establishme t entity to another one
 /// </summary>
 /// <param name="to"></param>
 /// <param name="from"></param>
 public static void CopyValues(this Adoxio_establishment to, Adoxio_establishment from)
 {
     to.Adoxio_establishmentid          = from.Adoxio_establishmentid;
     to.Adoxio_addresscity              = from.Adoxio_addresscity;
     to.Adoxio_addresspostalcode        = from.Adoxio_addresspostalcode;
     to.Adoxio_addressstreet            = from.Adoxio_addressstreet;
     to.Adoxio_alreadyopen              = from.Adoxio_alreadyopen;
     to.Adoxio_email                    = from.Adoxio_email;
     to.Adoxio_establishmentid          = from.Adoxio_establishmentid;
     to.Adoxio_expectedopendate         = from.Adoxio_expectedopendate;
     to.Adoxio_fridayclose              = from.Adoxio_fridayclose;
     to.Adoxio_fridayopen               = from.Adoxio_fridayopen;
     to.Adoxio_hasduallicence           = from.Adoxio_hasduallicence;
     to.Adoxio_isrural                  = from.Adoxio_isrural;
     to.Adoxio_isstandalonepatio        = from.Adoxio_isstandalonepatio;
     to.Adoxio_locatedatwinery          = from.Adoxio_locatedatwinery;
     to.Adoxio_locatedonfirstnationland = from.Adoxio_locatedonfirstnationland;
     to.Adoxio_mailsenttorestaurant     = from.Adoxio_mailsenttorestaurant;
     to.Adoxio_mondayclose              = from.Adoxio_mondayclose;
     to.Adoxio_mondayopen               = from.Adoxio_mondayopen;
     to.Adoxio_name                = from.Adoxio_name;
     to.Adoxio_occupantcapacity    = from.Adoxio_occupantcapacity;
     to.Adoxio_occupantload        = from.Adoxio_occupantload;
     to.Adoxio_parcelid            = from.Adoxio_parcelid;
     to.Adoxio_patronparticipation = from.Adoxio_patronparticipation;
     to.Adoxio_phone               = from.Adoxio_phone;
     to.Adoxio_saturdayclose       = from.Adoxio_saturdayclose;
     to.Adoxio_saturdayopen        = from.Adoxio_saturdayopen;
     to.Adoxio_sendmailtoestablishmentuponapproval = from.Adoxio_sendmailtoestablishmentuponapproval;
     to.Adoxio_standardhours      = from.Adoxio_standardhours;
     to.Adoxio_sundayclose        = from.Adoxio_sundayclose;
     to.Adoxio_sundayopen         = from.Adoxio_sundayopen;
     to.Adoxio_thursdayclose      = from.Adoxio_thursdayclose;
     to.Adoxio_thursdayopen       = from.Adoxio_thursdayopen;
     to.Adoxio_tuesdayclose       = from.Adoxio_tuesdayclose;
     to.Adoxio_tuesdayopen        = from.Adoxio_tuesdayopen;
     to.Adoxio_wednesdayclose     = from.Adoxio_wednesdayclose;
     to.Adoxio_wednesdayopen      = from.Adoxio_wednesdayopen;
     to.Createdon                 = from.Createdon;
     to.Importsequencenumber      = from.Importsequencenumber;
     to.Modifiedon                = from.Modifiedon;
     to.Overriddencreatedon       = from.Overriddencreatedon;
     to.Statuscode                = from.Statecode;
     to.Timezoneruleversionnumber = from.Timezoneruleversionnumber;
     to.Utcconversiontimezonecode = from.Utcconversiontimezonecode;
     to.Versionnumber             = from.Versionnumber;
 }
        public async Task <IActionResult> GetEstablishment(string id)
        {
            ViewModels.AdoxioEstablishment result = null;
            // query the Dynamics system to get the establishment record.

            Guid?adoxio_establishment_id       = new Guid(id);
            Adoxio_establishment establishment = null;

            if (adoxio_establishment_id != null)
            {
                try
                {
                    establishment = await _system.Adoxio_establishments.ByKey(adoxio_establishment_id).GetValueAsync();

                    result = establishment.ToViewModel();
                }
                catch (Microsoft.OData.Client.DataServiceQueryException dsqe)
                {
                    return(new NotFoundResult());
                }
            }

            return(Json(result));
        }
Example #6
0
 /// <summary>
 /// Copy values from a Dynamics establishme t entity to a view model.
 /// </summary>
 /// <param name="to"></param>
 /// <param name="from"></param>
 public static void CopyValues(this Adoxio_establishment to, ViewModels.AdoxioEstablishment from)
 {
     if (to.Adoxio_addresscity != from.Addresscity)
     {
         to.Adoxio_addresscity = from.Addresscity;
     }
     if (to.Adoxio_addresspostalcode != from.Addresspostalcode)
     {
         to.Adoxio_addresspostalcode = from.Addresspostalcode;
     }
     if (to.Adoxio_addressstreet != from.Addressstreet)
     {
         to.Adoxio_addressstreet = from.Addressstreet;
     }
     if (to.Adoxio_alreadyopen != from.Alreadyopen)
     {
         to.Adoxio_alreadyopen = from.Alreadyopen;
     }
     if (to.Adoxio_email != from.Email)
     {
         to.Adoxio_email = from.Email;
     }
     if (to.Adoxio_expectedopendate != from.Expectedopendate)
     {
         to.Adoxio_expectedopendate = from.Expectedopendate;
     }
     if (to.Adoxio_fridayclose != from.Fridayclose)
     {
         to.Adoxio_fridayclose = from.Fridayclose;
     }
     if (to.Adoxio_fridayopen != from.Fridayopen)
     {
         to.Adoxio_fridayopen = from.Fridayopen;
     }
     if (to.Adoxio_hasduallicence != from.Hasduallicence)
     {
         to.Adoxio_hasduallicence = from.Hasduallicence;
     }
     if (to.Adoxio_isrural != from.Isrural)
     {
         to.Adoxio_isrural = from.Isrural;
     }
     if (to.Adoxio_isstandalonepatio != from.Isstandalonepatio)
     {
         to.Adoxio_isstandalonepatio = from.Isstandalonepatio;
     }
     if (to.Adoxio_locatedatwinery != from.Locatedatwinery)
     {
         to.Adoxio_locatedatwinery = from.Locatedatwinery;
     }
     if (to.Adoxio_locatedonfirstnationland != from.Locatedonfirstnationland)
     {
         to.Adoxio_locatedonfirstnationland = from.Locatedonfirstnationland;
     }
     if (to.Adoxio_mailsenttorestaurant != from.Mailsenttorestaurant)
     {
         to.Adoxio_mailsenttorestaurant = from.Mailsenttorestaurant;
     }
     if (to.Adoxio_mondayclose != from.Mondayclose)
     {
         to.Adoxio_mondayclose = from.Mondayclose;
     }
     if (to.Adoxio_mondayopen != from.Mondayopen)
     {
         to.Adoxio_mondayopen = from.Mondayopen;
     }
     if (to.Adoxio_name != from.Name)
     {
         to.Adoxio_name = from.Name;
     }
     if (to.Adoxio_occupantcapacity != from.Occupantcapacity)
     {
         to.Adoxio_occupantcapacity = from.Occupantcapacity;
     }
     if (to.Adoxio_occupantload != from.Occupantload)
     {
         to.Adoxio_occupantload = from.Occupantload;
     }
     if (to.Adoxio_parcelid != from.Parcelid)
     {
         to.Adoxio_parcelid = from.Parcelid;
     }
     if (to.Adoxio_patronparticipation != from.Patronparticipation)
     {
         to.Adoxio_patronparticipation = from.Patronparticipation;
     }
     if (to.Adoxio_phone != from.Phone)
     {
         to.Adoxio_phone = from.Phone;
     }
     if (to.Adoxio_saturdayclose != from.Saturdayclose)
     {
         to.Adoxio_saturdayclose = from.Saturdayclose;
     }
     if (to.Adoxio_saturdayopen != from.Saturdayopen)
     {
         to.Adoxio_saturdayopen = from.Saturdayopen;
     }
     if (to.Adoxio_sendmailtoestablishmentuponapproval != from.Sendmailtoestablishmentuponapproval)
     {
         to.Adoxio_sendmailtoestablishmentuponapproval = from.Sendmailtoestablishmentuponapproval;
     }
     if (to.Adoxio_standardhours != from.Standardhours)
     {
         to.Adoxio_standardhours = from.Standardhours;
     }
     if (to.Adoxio_sundayclose != from.Sundayclose)
     {
         to.Adoxio_sundayclose = from.Sundayclose;
     }
     if (to.Adoxio_sundayopen != from.Sundayopen)
     {
         to.Adoxio_sundayopen = from.Sundayopen;
     }
     if (to.Adoxio_thursdayclose != from.Thursdayclose)
     {
         to.Adoxio_thursdayclose = from.Thursdayclose;
     }
     if (to.Adoxio_thursdayopen != from.Thursdayopen)
     {
         to.Adoxio_thursdayopen = from.Thursdayopen;
     }
     if (to.Adoxio_tuesdayclose != from.Tuesdayclose)
     {
         to.Adoxio_tuesdayclose = from.Tuesdayclose;
     }
     if (to.Adoxio_tuesdayopen != from.Tuesdayopen)
     {
         to.Adoxio_tuesdayopen = from.Tuesdayopen;
     }
     if (to.Adoxio_wednesdayclose != from.Wednesdayclose)
     {
         to.Adoxio_wednesdayclose = from.Wednesdayclose;
     }
     if (to.Adoxio_wednesdayopen != from.Wednesdayopen)
     {
         to.Adoxio_wednesdayopen = from.Wednesdayopen;
     }
     if (to.Createdon != from.Createdon)
     {
         to.Createdon = from.Createdon;
     }
     if (to.Importsequencenumber != from.Importsequencenumber)
     {
         to.Importsequencenumber = from.Importsequencenumber;
     }
     if (to.Modifiedon != from.Modifiedon)
     {
         to.Modifiedon = from.Modifiedon;
     }
     if (to.Overriddencreatedon != from.Overriddencreatedon)
     {
         to.Overriddencreatedon = from.Overriddencreatedon;
     }
     if (to.Statuscode != from.StatusCode)
     {
         to.Statuscode = from.StatusCode;
     }
     if (to.Statecode != from.StateCode)
     {
         to.Statecode = from.StateCode;
     }
     if (to.Timezoneruleversionnumber != from.Timezoneruleversionnumber)
     {
         to.Timezoneruleversionnumber = from.Timezoneruleversionnumber;
     }
     if (to.Utcconversiontimezonecode != from.Utcconversiontimezonecode)
     {
         to.Utcconversiontimezonecode = from.Utcconversiontimezonecode;
     }
     if (to.Versionnumber != from.Versionnumber)
     {
         to.Versionnumber = from.Versionnumber;
     }
 }
Example #7
0
        /// <summary>
        /// Convert a establishme t entity to a model
        /// </summary>
        /// <param name="from"></param>
        /// <returns></returns>
        public static Adoxio_establishment ToModel(this ViewModels.AdoxioEstablishment from)
        {
            Adoxio_establishment result = null;

            if (from != null)
            {
                result = new Adoxio_establishment();

                result.Adoxio_establishmentid           = new Guid(from.id);
                result._adoxio_licencee_value           = from._licencee_value;
                result._adoxio_licencetypeid_value      = from._licencetypeid_value;
                result._adoxio_municipality_value       = from._municipality_value;
                result._adoxio_policejurisdiction_value = from._policejurisdiction_value;
                result._adoxio_primaryinspectorid_value = from._primaryinspectorid_value;
                result._adoxio_territory_value          = from._territory_value;
                result._createdby_value          = from._createdby_value;
                result._createdonbehalfby_value  = from._createdonbehalfby_value;
                result._modifiedby_value         = from._modifiedby_value;
                result._modifiedonbehalfby_value = from._modifiedonbehalfby_value;
                result._ownerid_value            = from._ownerid_value;
                result._owningbusinessunit_value = from._owningbusinessunit_value;
                result._owningteam_value         = from._owningteam_value;
                result._owninguser_value         = from._owninguser_value;
                result.Adoxio_addresscity        = from.Addresscity;
                result.Adoxio_addresspostalcode  = from.Addresspostalcode;
                result.Adoxio_addressstreet      = from.Addressstreet;
                result.Adoxio_alreadyopen        = from.Alreadyopen;
                result.Adoxio_email                    = from.Email;
                result.Adoxio_expectedopendate         = from.Expectedopendate;
                result.Adoxio_fridayclose              = from.Fridayclose;
                result.Adoxio_fridayopen               = from.Fridayopen;
                result.Adoxio_hasduallicence           = from.Hasduallicence;
                result.Adoxio_isrural                  = from.Isrural;
                result.Adoxio_isstandalonepatio        = from.Isstandalonepatio;
                result.Adoxio_locatedatwinery          = from.Locatedatwinery;
                result.Adoxio_locatedonfirstnationland = from.Locatedonfirstnationland;
                result.Adoxio_mailsenttorestaurant     = from.Mailsenttorestaurant;
                result.Adoxio_mondayclose              = from.Mondayclose;
                result.Adoxio_mondayopen               = from.Mondayopen;
                result.Adoxio_name                = from.Name;
                result.Adoxio_occupantcapacity    = from.Occupantcapacity;
                result.Adoxio_occupantload        = from.Occupantload;
                result.Adoxio_parcelid            = from.Parcelid;
                result.Adoxio_patronparticipation = from.Patronparticipation;
                result.Adoxio_phone               = from.Phone;
                result.Adoxio_saturdayclose       = from.Saturdayclose;
                result.Adoxio_saturdayopen        = from.Saturdayopen;
                result.Adoxio_sendmailtoestablishmentuponapproval = from.Sendmailtoestablishmentuponapproval;
                result.Adoxio_standardhours      = from.Standardhours;
                result.Adoxio_sundayclose        = from.Sundayclose;
                result.Adoxio_sundayopen         = from.Sundayopen;
                result.Adoxio_thursdayclose      = from.Thursdayclose;
                result.Adoxio_thursdayopen       = from.Thursdayopen;
                result.Adoxio_tuesdayclose       = from.Tuesdayclose;
                result.Adoxio_tuesdayopen        = from.Tuesdayopen;
                result.Adoxio_wednesdayclose     = from.Wednesdayclose;
                result.Adoxio_wednesdayopen      = from.Wednesdayopen;
                result.Createdon                 = from.Createdon;
                result.Importsequencenumber      = from.Importsequencenumber;
                result.Modifiedon                = from.Modifiedon;
                result.Overriddencreatedon       = from.Overriddencreatedon;
                result.Statuscode                = from.StatusCode;
                result.Statecode                 = from.StateCode;
                result.Timezoneruleversionnumber = from.Timezoneruleversionnumber;
                result.Utcconversiontimezonecode = from.Utcconversiontimezonecode;
                result.Versionnumber             = from.Versionnumber;
            }
            return(result);
        }
Example #8
0
        public async System.Threading.Tasks.Task TestCRUD()
        {
            string initialName = "InitialName";
            string changedName = "ChangedName";

            var loginUser = randomNewUserName("NewLoginUser", 6);
            var strId     = await LoginAndRegisterAsNewUser(loginUser);

            // C - Create
            var request = new HttpRequestMessage(HttpMethod.Post, "/api/" + service);

            Adoxio_establishment adoxio_establishment = new Adoxio_establishment()
            {
                Adoxio_establishmentid = Guid.NewGuid(),
                Adoxio_name            = initialName
            };


            ViewModels.AdoxioEstablishment viewmodel_adoxio_establishment = adoxio_establishment.ToViewModel();

            string jsonString = JsonConvert.SerializeObject(viewmodel_adoxio_establishment);

            request.Content = new StringContent(jsonString, Encoding.UTF8, "application/json");

            var response = await _client.SendAsync(request);

            response.EnsureSuccessStatusCode();

            // parse as JSON.
            jsonString = await response.Content.ReadAsStringAsync();

            ViewModels.AdoxioEstablishment responseViewModel = JsonConvert.DeserializeObject <ViewModels.AdoxioEstablishment>(jsonString);

            // name should match.
            Assert.Equal(initialName, responseViewModel.Name);
            Guid id = new Guid(responseViewModel.id);

            // R - Read

            request  = new HttpRequestMessage(HttpMethod.Get, "/api/" + service + "/" + id);
            response = await _client.SendAsync(request);

            response.EnsureSuccessStatusCode();

            jsonString = await response.Content.ReadAsStringAsync();

            responseViewModel = JsonConvert.DeserializeObject <ViewModels.AdoxioEstablishment>(jsonString);
            Assert.Equal(initialName, responseViewModel.Name);

            // U - Update
            adoxio_establishment.Adoxio_name            = changedName;
            adoxio_establishment.Adoxio_establishmentid = id;

            request = new HttpRequestMessage(HttpMethod.Put, "/api/" + service + "/" + id)
            {
                Content = new StringContent(JsonConvert.SerializeObject(adoxio_establishment.ToViewModel()), Encoding.UTF8, "application/json")
            };
            response = await _client.SendAsync(request);

            jsonString = await response.Content.ReadAsStringAsync();

            response.EnsureSuccessStatusCode();

            // verify that the update persisted.

            request  = new HttpRequestMessage(HttpMethod.Get, "/api/" + service + "/" + id);
            response = await _client.SendAsync(request);

            response.EnsureSuccessStatusCode();

            jsonString = await response.Content.ReadAsStringAsync();

            responseViewModel = JsonConvert.DeserializeObject <ViewModels.AdoxioEstablishment>(jsonString);
            Assert.Equal(changedName, responseViewModel.Name);

            // D - Delete

            request  = new HttpRequestMessage(HttpMethod.Post, "/api/" + service + "/" + id + "/delete");
            response = await _client.SendAsync(request);

            response.EnsureSuccessStatusCode();

            // second delete should return a 404.
            request  = new HttpRequestMessage(HttpMethod.Post, "/api/" + service + "/" + id + "/delete");
            response = await _client.SendAsync(request);

            Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);

            // should get a 404 if we try a get now.
            request  = new HttpRequestMessage(HttpMethod.Get, "/api/" + service + "/" + id);
            response = await _client.SendAsync(request);

            Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);

            await LogoutAndCleanupTestUser(strId);
        }